+ 1

How to end input in c?

How to end input with entering zero or any number????

21st Jan 2021, 3:23 PM
Hakk123
Hakk123 - avatar
4 Antworten
+ 1
there are mant ways to do this you can use loop and if number==0 then break use such types of conditions Use like this while (scanf("%d",& variable)>0) { }
21st Jan 2021, 3:26 PM
A S Raghuvanshi
A S Raghuvanshi - avatar
+ 1
It depends! If your program only accepts ASCII numerals to perform an action, then checking the char returned by getchar() may be enough. If your program is parsing string commands then you could do something like this: https://code.sololearn.com/ca34a18A146A For range-based input you have two alternatives: 1. You can ask the user up front how many values should be entered. 2. End the loop if a blank line (or a specific value is entered). Which one of these are the most effective depends on what kind of input you're dealing with.
21st Jan 2021, 7:42 PM
Mike A
Mike A - avatar
+ 1
Just use a while loop and comapre the input with your number and use break statement when you got the right number! That's all
21st Jan 2021, 10:55 PM
Hisham YUM 🇲🇦
Hisham YUM 🇲🇦 - avatar
+ 1
thank you for helping me ♨️♨️ Hisham YUM 🇲🇦 Jegix
22nd Jan 2021, 2:23 PM
Hakk123
Hakk123 - avatar