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?

First of all: What Dragon said.

Why am I getting 'call of nonfunction' every time I use word(j)? What am I doing wrong?

Use word[j] instead of word(j) (square brackets)

Edited 6 Years Ago by Nick Evan: n/a

fscanf() will read just one word at a time, which will greatly simplify the solution to the problem.

True, but you learn nothing about how to parse a string, which I would assume is the lesson to be learned here.

True, but you learn nothing about how to parse a string, which I would assume is the lesson to be learned here.

we don't know that because he didn't say what the purpose of the lesson is. It could be just to learn file i/o.

This question has already been answered. Start a new discussion instead.