It turns out that all alert The return value will be preceded by a number of newlines and spaces. I still don't understand , The same computer , Same as If the fields in the entity class and database table are not consistent Changed properties.
To regenerate the getter and setter also toString Method In the test class , relevant set You will report errors in all the methods you use. Just change to the latest set The method is ok. Recuperate at home , I have nothing to watch C primer plus, See the book for scanf Input judgment , The following methods are commonly used : At this point it will return 1 Consider my input successful , If not for 1 It is regarded as input failure.
In the end scanf What does the return value of refer to? But never again in a project finally In the code block return sentence , That's because it's very easy to produce " misunderstand ", It will be serious If you want to setup There is a return value , For subsequent operations A stay setup The required return value in the keyword , Set to global variable perhaps suit variable: Here's the picture : But in the compiler , Will report a mistake , But to perform That is because, once the first scanf failed, it is probably because of matching failure, and the input which caused the matching failure, remains inside the input buffer, waiting to be consumed by next call.
Thus, the next call to scanf also try to consume the same invalid input residing in the input buffer immediately, without waiting for the explicit external user input as the input buffer is not empty. Solution: After the first input fails for scanf , you have to clean up the input buffer, for a trivial example, something like while getchar!
The scanf family of functions reads data from the console or from a FILE stream, parses it, and stores the results away in variables you provide in the argument list.
But it also has additional capabilities, most notably that it can eat up other characters in the input that you specify in the format string. What's happening is scanf is pattern matching the format string kind of like a regular expression.
In your second example, scanf reads in a number and stores it in x. But it has not yet reached the end of the format string -- there is still a space character left. So scanf reads additional whitespace character s from standard input in order to try to match it. The behavior is undefined. If you are migrating older code you might see LNK in connection with these functions.
Returns the number of fields successfully converted and assigned; the return value does not include fields that were read but not assigned.
A return value of 0 indicates that no fields were assigned. The scanf function reads data from the standard input stream stdin and writes the data into the location given by argument. Each argument must be a pointer to a variable of a type that corresponds to a type specifier in format. If copying takes place between strings that overlap, the behavior is undefined. For more information, see Format Specification Fields — scanf functions and wscanf Functions.
0コメント