I\'m beginning to code in C. My code is as follows:
#include
#include
#include
#define MAX_STR_LEN 256
#de
In the while loop:
while (fgets(buf, 255, bookFile) != NULL)
you are copying into the memory location of buffer new contents from file. As tmp points to a certain point in the buffer, its contents are being replaced too.
tmp = strtok(NULL, ";");
books[i].name = tmp;
You should allocate memory for each struct of the array and then use strcopy.
You can find an explanation of differences between strcpy and strdup here: strcpy vs strdup