I am a beginner in C and am having a problem when mapping documents into a file, because some lines contain null characters, how can I fix this?
Code:
void mapFilePositional(const char *breaker, int breakerPosition, document **documents, FILE **input){
char *buffer;
unsigned int pivot = 0,
lineSize = 0,
breakerSize = strlen(breaker);
unsigned long position = 0;
buffer = (char*)malloc(BUFFER_SIZE * sizeof(char));
while(fgets(buffer, BUFFER_SIZE, *input) != NULL){
if(strncmp((buffer + breakerPosition - 1), breaker, breakerSize) == 0){
if((pivot % DOCUMENT_SIZE) == 0){
if(allocateDocument(documents, DOCUMENT_SIZE * ((pivot % DOCUMENT_SIZE) + 1)) == 0){
printf("Error: error to allocate struct.!\n");
abort();
}
}
(*documents + pivot)->initialPosition = position;
(*documents + pivot)->size = lineSize;
position += lineSize;
lineSize = 0;
pivot++;
}
lineSize += strlen(buffer);
}
free(buffer);
}