This program is to stay in a hotel, input the correct number of days, only captures the input number function part, There are two don't understand. (1) the conditions in the while loop, I understood as when days are 1, not into the circulation, enter not into the loop when 1 (but is not in conformity with the simply enter again the purpose of the correct number of days), Can run, no matter what I input Numbers (including 1) will not enter the circulation, (that is, the application meets the requirements) That this program is right, is to meet the requirements, but my understanding of them is wrong, ask god to solve!
2 cycles of the scanf (' * '% s') What is the role of (1) * (2) why do you want to join this statement here? (after I get rid of this statement, the program may enter the infinite loop, I can't understand why)
CodePudding user response:
The scanf return values ranging from 1 (note that only one of the scanf % d, therefore is equal to 1 is normal input), shows that the input does not match the % d, then the scanf (" % s "); In the cache is used to receive input does not match the contents of % d, so that ensure the input cache does not contain the content, the next time the scanf will receive new input, without it, so the content of the input buffer will and % d match, do not match, continue to return zero, thus became an infinite loop