Home > Back-end >  Can ask why must add this line to deal with non integer input code? Why not add other integer progra
Can ask why must add this line to deal with non integer input code? Why not add other integer progra

Time:12-09

Int getnights (void)
{
Int nights;
Printf (" do enter the days you want to live: \ n ");
While (the scanf (" % d ", & amp; Nights)!
=1){
the scanf (" % s ");//handle the integer input
Printf (" both Please enter an integer, sun as 2. \ n ");
}
Return nights;
}

CodePudding user response:

For string, no superfluous

CodePudding user response:

reference 1/f, Simple, Soft reply:
for strings, no redundant

Can explain why the input letters slightly subclass is not all because of a carriage return character in the reason?

CodePudding user response:

Why do you want to * s? Character % s is a string,
Because you are integer variables, so you will get a small number of omission,
If you want to define other input with a decimal, such as double types, input use % lf good!
% % s is a character type c, you lose in also not ah, losing a digital implicit conversion may not succeed, this I haven't written so, not too clear, but you lose the letters to digital variables, will certainly be a problem, not just a single character

CodePudding user response:

MSDN mentioned
An asterisk (*) following the percent sign suppresses the assignment of the next input field, which is interpreted as a field of the specified type. The field is scanned but not stored.
Mean, roughly the scanf () function parameters, add an asterisk behind percent *, said an asterisk after all the parameters are invalid, the use of an asterisk is to read the contents of the stream, but does not store the content,
  • Related