teacher is looping my while-switch by inputing a char.

Pages: 12
Dec 6, 2009 at 9:48pm
so the results are how many times items were successfully read. and the only reason it is unable to read the letter is because of the format specifier?
Dec 6, 2009 at 9:52pm
What does the documentation say it returns? What does it return in your program?

Read the documentation that both firedraco and I pointed you to (and that you failed to comprehend) and ask yourself "is scanf() going to be able to successfully convert the letter my teacher just entered to the integer I asked it to input?" The answer to that question should tell you what scanf() returns.
Dec 6, 2009 at 10:01pm
but thats what im saying i DONT want it to convert the letter to a number. my program ask's for a number input not a letter input. my teacher is putting in a letter to send it on a infinite loop. in other words she is trying to mess the program up somehow i know %d is for numbers and i know that %s is for letters but how do i stop the infinite loop when she enters a letter(which isnt surposed to be in there)
Dec 6, 2009 at 10:17pm
In my example code, tell me exactly what the contents of "result" and "item" are after:

A) entering "1"

and

B) entering "A"

And then tell me what you think you can do with that information.
Dec 6, 2009 at 10:20pm
but mine is in a while with a switch statment so when one is entered in mine it goes to the 1st case but if a is entered it goes on a infinite loop. how can i stop the loop?
Dec 6, 2009 at 10:31pm
You must answer my question (correctly) before I answer yours.
Dec 6, 2009 at 10:33pm
ok with your program it will execute whatever is in the if statement when "1" is put in


if you put "A" in then it doesnt execute what is in the if
Dec 6, 2009 at 10:37pm
The correct answer to my question is in the form of
result = x
item = y

I did not ask what it does.
Dec 6, 2009 at 10:39pm
ok so result = x and item = y. keep explaining please
Dec 6, 2009 at 10:47pm
Ugh. After his code executes, what is result equal to, and item equal to, if he inputs 1? And, separately, what is result equal to, and item equal to, if he inputs the letter A? Run it through a debugger or something and see, or use the reference section of this site as has been suggested.
Dec 7, 2009 at 3:35pm
oh man. i just tried it. checking for error isn't enough. the buffer has to be flushed somehow.
Topic archived. No new replies allowed.
Pages: 12