infinite loop

This is a discussion on infinite loop within the C Programming forums, part of the General Programming Boards category; anybody know what i need to do to get rid of the infinite loop?
Code:
do
{
printf("Enter the number ...

Assuming test is of type int, there is no infinite loop in that code fragment, unless the user enters junk characters that cannot be interpreted as an integral value

Entering a value between 0 and 4 will terminate it.

If you want to allow the user to enter junk data and not have the program loop forever, use fgets() to read a line of input (as a character string) then check the characters before using sscanf() to parse the string.

Alternatively, check the return value of scanf() to see if it succeeded in reading an int. If the return value indicates no integer was read, read a character, discard that character, and go again.

Read the documentation for scanf() to get an idea of what it's return values mean.

If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

Yeah when i run it and enter a wrong number it will keep saying Wrong number. Please try again! I need it to say that and then prompt the user to type the number in again until they type one that fits but I can't seem to figure out how with the loop.

You are complaining about the code doing exactly what it is supposed to. It will loop until the user enters an integral value between 0 and 4.

I've already described options for handling the user who enters rubbish characters (which would cause your code snippet, as written, to repeatedly complain about a wrong value, but not accept any further input).

If I seem grumpy or unhelpful in reply to you, or tell you you need to demonstrate more effort before you can expect help, it is likely you deserve it. Suck it up, Buttercup, and read this, this, and this before posting again.

You are complaining about the code doing exactly what it is supposed to. It will loop until the user enters an integral value between 0 and 4.

I've already described options for handling the user who enters rubbish characters (which would cause your code snippet, as written, to repeatedly complain about a wrong value, but not accept any further input).

not really complaining, i came here with a problem seeking help to fix it, after all isnt this what this website is for? as for the fgets and sscanf, we havent learned those yet so i cant use those for my code. i tried a few different things with for loops and also tried changing the while loop but its still giving me that infinite loop when the user enters rubbish/wrong number.

If you provide the full code, and tell us the input you're giving the program when this happens, it might help us see if something else is going awry somehow. Based on what you've told us, everything should be working as expected, which makes it difficult to "fix."

You also didn't mention whether you tried grumpy's advice in post #2, about checking the return value of "scanf()."

i had this part working earlier but i changed some stuff and now i cant figure out how to get this part to work correctly again. i know its a simple problem but i guess im just burnt out because i cant find what im doing wrong!