Home > Back-end >  While the use of the help!!!!!!!!!!!!!!!!
While the use of the help!!!!!!!!!!!!!!!!

Time:05-24

Is the same meaning, but why not write together and separate results as
Ch=fgetc (fp);
While (ch!=(EOF)
{
If (ch=='\ n')
{
count++;
}
}
Printf (" % d \ n ", count);
The result is jam,

However,
While ((ch=fgetc (fp))!=(EOF)
{
If (ch=='\ n')
{
count++;
}
}
Printf (" % d \ n ", count);
This can play out the value of the count, according to? !!!!!!!!!!!!!!!!!!

CodePudding user response:

The first writing, in the while loop, ch did not change, will certainly into dead circulation,
The second kind of writing, every time the while loop, ch will again be fgetc (fp) assignment, always read the EOF, so they can jump out of the loop,

CodePudding user response:

The first ch=fgetc (fp); In the while () loop in vitro, ch reads from the file only once, as long as this time is not in the end-of-file, while (ch!=(EOF) come true forever, dead cycle,
  • Related