c = getchar()) != ' N' and for loop

learnedfor loop,In practice when it came to getchar()) != ‘n’ The problem。I.e.while loopSo that in thefor loopEnter the void (to be treated as a character。)

All to known,getchar functionUsed to get the character,And if the direct use in a loop,It found that the situation will not be able to press enter characters into the system。The reason is the carriage return character is so ~,Enter the same time we want to join it is " \n "Discrimination,That has getchar()!='n' ,With this approach while Circulation work well,Available at for Under cycling there are many novice shouted ineffective。

= = I was one of them。

What we do know is for The format of this cycle is:

 

so,According to my understanding,Use a for loop to get the input string should be like a child

Enter decisive executable found still useless,Resolute character is treated as a system to deal with。After Google found the problem hehe

original,exist for(c = getchar();c != 'n';) in c = getchar() Before execution cycle,That is circulating in a separate statement executed,Natural Enter "invalid",which is !='n' Needs and c = getchar() Write together,As a condition for loop execution,So each for loop,As long as the establishment of a second conditional statement,Will be executed。

Original article written by LogStudio:R0uter's Blog » c = getchar()) != ' N' and for loop

Reproduced Please keep the source and description link:https://www.logcg.com/archives/131.html

About the Author

R0uter

The non-declaration,I have written articles are original,Reproduced, please indicate the link on this page and my name。

Leave a Reply

Your email address will not be published. Required fields are marked *