[PTA报错]warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result

Always appears as the title when the title PTA brush shown in error - Warning: Ignore 'scanf' return value, with property warn_unused_result statement like, so the cause of the error and the solution appears to do the inspection.

the reason

We often can be seen in the compiler to warn untreated scanf return value, but we often choose to ignore, PTA too strict! Only address this warning, but unfortunately ~
first scanf function's return value reflects the character in the specified format to read the correct number of data. The number of entries obtained input value is not necessarily equal, nor is the number of the incoming data buffer.
If the input data does not match the specified format, it will produce input errors. Input errors encountered, scanf function will terminate immediately return data (ie, read into the correct) number has been successfully read.
Therefore, by the function scanf return specified value and the number of input data (determined by the character format) the comparison can be determined whether the data was successful .
j terms of security, in most cases it should not ignore the return value of scanf, so they gave it a property warn_unused_result, tells the compiler gives you a warning, if you really do not need the return value, then there is no problem. But it is usually best to check to make sure you really think you successfully read the content they read.

Solution

Gangster attach a variety of solutions, after several more simple, suggest that you read the code above English explanation of each method, we can more clearly understand why this was able to solve a / shield this warning, linked below.
Can someone help me understand this warning? ( Solutions)

Published 21 original articles · won praise 2 · Views 3386

Guess you like

Origin blog.csdn.net/weixin_44164333/article/details/104470106
Recommended