Hi guys, I'm writing a program that works like a phone book
Im having a lot of problems dealing with the fgets() function
Everything works fine except the readSaved() function, the program always crashs on me when it reaches the fgets() function and I have no idea how to fix that, any suggestions?
Code:
int readSaved(struct Contact contact[])
{
FILE *fp;
int max = 2*NAMELENGTH + 2*PHONELENGTH;
char *line, *token;
int i = 0;
if((fp = fopen(FILENAME, "r")) != NULL)
{
fgets(line, max, fp);
//printf("Readed first line\n");
while((int)line != EOF)
{
//printf("Into loop\n");
//printf("%s\n", line);
token = strtok(line, " ");
contact[i].first= token;
token = strtok(NULL, " ");
contact[i].last = token;
token = strtok(NULL, " ");
contact[i].home = token;
token = strtok(NULL, "\n");
contact[i].cell = token;
i++;
fgets(line, max, fp);
}
fclose(fp);
}
return i;
}