Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- typedef struct BufferDescriptor {
- char * ca_head ;
- int capacity ;
- char inc_factor;
- int addc_offset ;
- int mark_offset ;
- char r_flag;
- char mode;
- } Buffer ;
- int b_reset ( Buffer *pB )
- {
- Buffer *temp = NULL;
- int i = 0;
- int j = 1;
- if (pB == NULL)
- {
- return R_FAIL_1;
- }
- else
- {
- temp = (Buffer*)malloc(sizeof(Buffer*));
- if (temp == NULL)
- {
- return R_FAIL_1;
- }
- temp->ca_head = (char*)malloc(pB->capacity);
- if (!temp->ca_head)
- {
- temp = NULL;
- return R_FAIL_1;
- }
- for(i = 0;i < ca_getsize(pB);++i)
- {
- temp->ca_head[j] = pB->ca_head[i];
- j++;
- }
- pB->ca_head = temp->ca_head;
- //free(temp->ca_head);
- //free(temp);
- return 0;
- }
- }
- temp->ca_head[0] = 'a';
- temp->ca_head[1] = 'b';
- temp->ca_head[2] = 'c';
- temp->ca_head[3] = 'd';
- temp->ca_head[4] = 'e';
- b_reset(temp); //this will return the size as 0, when it's actually 5
- //temp->ca_head[0] = 'i'; //if this is executed, it returns the size as 6
- //and prints out the right values, but if it's not,
- //it will not print out anything
- printf("%d", ca_getsize(temp));
- for(i = 0;i < ca_getsize(temp);++i)
- {
- printf("%c", temp->ca_head[i]);
- }
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <assert.h>
- #define R_FAIL_1 1
- #define BUFFER_SIZE 10
- typedef struct BufferDescriptor {
- char * ca_head ;
- int capacity ;
- char inc_factor;
- int addc_offset ;
- int mark_offset ;
- char r_flag;
- char mode;
- } Buffer ;
- void allocate_buffer(Buffer *pB, int size)
- {
- pB->ca_head = malloc(size);
- assert(pB->ca_head);
- pB->capacity = size;
- }
- int ca_getsize( Buffer *pB)
- {
- return pB->capacity;
- }
- int b_reset ( Buffer *pB )
- {
- int i = 0;
- if (pB == NULL)
- {
- return R_FAIL_1;
- }
- else
- {
- if ( ca_getsize(pB) <= 0 || pB->ca_head == NULL )
- return R_FAIL_1;
- }
- // shift data up by 1 byte
- for( i = ca_getsize(pB) - 1 ; i > 0;i-- )
- {
- pB->ca_head[i] = pB->ca_head[i-1];
- }
- pB->ca_head[0] = '