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?

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

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)

Great, thanks. I can't believe how simple this actually is.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.