C Programming - Handling string input when the program requires an int

preview_player
Показать описание
Strategies for handling scanf statements that require and int %d when the user types in characters. Use the result of scanf to determine if an int was read in. If it was not, exit or read past the character input and let the user try again.
Рекомендации по теме
Комментарии
Автор

thank you so much, I couldn't find any other video talking about this. I was just about to quit

maxpro
Автор

this video was a lifesaver, i was stressing out so much with this, thank you so much

bruno-zydn
Автор

thanks a lot. this helped me with my school lab.

lofi_ish
Автор

well, at the place of scanf("%*[^\n]");
fflush(stdin); can also be used...

thanks for you help!😃

kumarvaibhav
Автор

Thanks for sharing awesome content. Also, make sure to add tags along with your videos to get reach to bigger audience

BoogeymanChannel
Автор

Thanks for this. Lol I was struggling so much before this.

thesunfirecape
Автор

Thankyou so much for this:)
U earned a subscriber

santhanamkumarn
Автор

how about if i entered a combination of numbers and letters? my program requires integers. for example, i put "98eg" it should return an error too. but when i entered 98 only, it'll perform what my program is supposed to do

moonlightsemislowed
Автор

Hi! It is a great video. But when I entered "3g", the scanf only recognizes 3 and skipped "g". What should I do in this case then

theanguyen
Автор

hello do u have some of this but in char

geoffandrei
Автор

is that an online editor you're using ?

devoiddude
Автор

Or... just read a string and parse the integer. That is the easier way.
scanf is not intended to be used as user input. scanf is a formatted input and, such as, you need to know all types of the input and the sequence of their occurrence. And that info is into the man page.
C is not for beginners!

andredcavalcante
Автор

The code is not fool proof for entering decimals

kwesiafari