I want to loop through a text file and concatenate all the strings until a blank line is hit and then do the same for the next strings and so on. The result of each string concatenation should be added to an char* array:
char* element_arr[287];
void splitPassports(FILE* file_to_read){
char element[500];
char str[80];
int i = 0;
int j = 0;
while(j < FILELENGTH){
if (fgets(str,80, file_to_read) && !isBlank(str)){
strcat(element,str);
printf("The string is: %s\n",str);
}else if (isBlank(str)){
element_arr[i] = element;
memset(element, '\0', sizeof element);
printf("%s\n",element_arr[0]);
i++;
}
j++;
}
fclose(file_to_read);
}
However when I try to do this I get an illegal hardware instruction error (I'm on a Mac). How can I properly add the new strings to the existing one and then append that to my array and after that set it back to zero to do the same for the few lines until a blank line is hit? I'm relatively new to C so thanks in advance :)