Pardon me if I'm way off base (seeing as I am a newbie myself), but I think what happens is that your loop waits for a keypress (getchar()), checks to see if c=='x', then breaks regardless -- your if statement ends in a semicolon, thus you are doing nothing if the if statement is true -- (I think) you need to drop that semicolon.
Hope that helps!
Christian Schmidt <sm...@xs...> wrote:
When I run this code it exits after any key I press. What am I doing wrong?
#include
main ( )
{
int c;
printf ("Enter a character:\n(Enter x to exit\n");
while (1)
{
c = getchar ( );
if (c == 'x');
break;
}
printf ("Exiting the loop now!\n");
return 0;
}
Thanks
-------------------------------------------------------
This SF.net email is sponsored by: ObjectStore.
If flattening out C++ or Java code to make your application fit in a
relational database is painful, don't do it! Check out ObjectStore.
Now part of Progress Software. http://www.objectstore.net/sourceforge
_______________________________________________
Dev-cpp-users mailing list
Dev...@li...
TO UNSUBSCRIBE: http://www.noicys.cjb.net/devcpp/ub.htm
https://lists.sourceforge.net/lists/listinfo/dev-cpp-users
---------------------------------
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo.
---------------------------------
Do you Yahoo!?
The New Yahoo! Search - Faster. Easier. Bingo. |