OK, this is the problem: my original file has only one line and that line contains a sentence. I'm supposed to create a new file that will put each word from the sentence in its own line. For example,
original file:
The quick fox jumped over the lazy dog
output file:
The
quick
fox
jumped
over
the
lazy
dog
I am using fgets because the string in the original file has spaces.
main(){
FILE *a,*b;
char word[200];
int j=0;
a=fopen("C:\\C_fajlovi\\gr3zad3.txt","r");
if(a==NULL) exit(1);
b=fopen("C:\\C_fajlovi\\zad3.txt","w");
if(b==NULL) exit(1);
while(fgets(word,strlen(word)+1,a)!=NULL){ /*word=the entire sentence*/
while(word(j)!=' ' && word(j)!='\0'){
fprintf(b,"%c",word(j));
j++;
}
fprintf(b,"\n");
j++;
}
}
Why am I getting 'call of nonfunction' every time I use word(j)? What am I doing wrong?