#include
The main ()
{
FILE* fp;
Char ch, filename [50];
Printf (" please enter the file name: \ n ");
The scanf (" % s ", filename);
If (fp=fopen (filename, "w")==NULL)
{
Printf (" error ");
exit(0);
}
Ch=getchar ();
Ch=getchar ();
While (ch!='#')
{
Fputc (ch, fp);
Ch=getchar ();//don't understand the role of the
}
}
Overall is the input string to a TXT document
According to knock the book, but can not reach the desired results, using vs2019, at the end of the TXT documents or empty,
CodePudding user response:
Ch=getchar () is to continue to extract characters from the input buffer.If not, you while (ch! Ch='#') values will not change, not die cycle?
Fputc ch output to the file only, won't change the value of the ch so need ch=getchar () to obtain the next character
CodePudding user response: