Home > Back-end >  The novice daily for help
The novice daily for help

Time:12-11

#include
#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:

reference 1st floor qybao 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 get the next character

Don't understand the

CodePudding user response:

refer to the second floor m0_46570923 response:
Quote: refer to 1st floor qybao 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 get the next character

Don't understand the

Understand understand ( ̄?  ̄)! Thank you very much!

CodePudding user response:

 # include & lt; stdio.h> 
#include
Int main ()
{
FILE* fp;
Char ch, filename [50];
Printf (" please enter the file name: \ n ");
The scanf (" % s ", filename);
//if (fp=fopen (filename, "w")==NULL)
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
}
}

For your reference ~

Note that is greater than the===priority (assignment), so the back of the first,

CodePudding user response:

Thank you for telling me these things! Thank you very much

CodePudding user response:

What do you all have no input

CodePudding user response:

refer to 6th floor lstalen response:
what do you have no input

Input! But nothing at all? ! Has solved the problem but still very thank you can answer my question
  • Related