Home > Back-end >  Oj the last line of the no newline, test data files directly over, can use getchar judgment
Oj the last line of the no newline, test data files directly over, can use getchar judgment

Time:10-06

Language is c + +
Title requires:
Input data may have a newline after the last line, is also likely to end of file directly, without line breaks

The code I wrote is:
Char p;
P=getchar ();
While (p!=EOF& & p!='\ n') {
.
}

In visual studio input CTRL plus z does not execute the next step, excuse me poj on this will lead to the last line of the input to output the results you
Thank you big!

CodePudding user response:

You there are more lines in the input data input? So this is the right loop,
In fact use!=EOF is enough, in the loop when a newline is not processing or to do special processing

CodePudding user response:

To determine EOF
Your p cannot be defined as a char
Instead of int
  • Related