Hi, how do i prevent them from entering letters when i ask for numbers, using scanf
Hi, how do i prevent them from entering letters when i ask for numbers, using scanf
also what does this mean
printf ("%d", scanf("%d", &var));
? Does this return 1 if the variable is filled, and 0 if its null?
thanks
You can't.Originally Posted by renderstream
Read: http://faq.cprogramming.com/cgi-bin/...&id=1043284385
>> printf ("%d", scanf("%d", &var));
Read up on what scanf() returns to understand what gets printed.
When all else fails, read the instructions.
If you're posting code, use code tags: [code] /* insert code here */ [/code]
You can't do it with scanf alone. A common way to pre process input is to read stdin using fgets, scan the buffer for the expected characters, then call sscanf to put the input into the proper variables, or let the user know they messed up and ask them to try again.Originally Posted by renderstream
It's a lot of work, and there are easier ways... one reason scanf is seldom used.
-Rog