I'm making a function to count the number of words in a file but as soon as it reaches the fscanf the program crashes with the aforementioned return value.
i'm making a program to build a binary tree and i thought at first that it's crashing because of some pointer error or something but i commented out the rest of the code and it still gives the error;
include stdio.h
include stdlib.h
include string.h
FILE *file;
typedef struct Node{
struct Node* left;
struct Node* right;
struct Node* parent;
char *word;
}Node;
typedef struct{
Node* root;
int maxlen;
}tree;
int getCount()
{
int count=0;
file=fopen("hi.txt","r");
while(!feof(file))
{
count++;
fscanf(file,"%s\n");
}
fclose(file);
return count;
}
int main()
{
int count=getCount();
printf("count=%d",count);
/*tree t;
buildbase(&t,getMaxmin(count),count);*/
return 0;
}
the code worked yesterday and i didn't change anything in this function and it produced 98915