RE: [Dev-C++] Why is this code not doing what it should do? (simple example code from book)
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Smurf, P. <smu...@xs...> - 2003-05-25 23:55:41
|
I found the error
if (c == 'x');
break;
should be
if (c=='x') <--- no semi colon here!!
break;
Bye
> -----Original Message-----
> From: dev...@li...
> [mailto:dev...@li...]On Behalf Of Christian
> Schmidt
> Sent: maandag 26 mei 2003 1:36
> To: dev...@li...
> Subject: [Dev-C++] Why is this code not doing what it should do? (simple
> example code from book)
>
>
> When I run this code it exits after any key I press. What am I
> doing wrong?
>
> #include <stdio.h>
>
> 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
>
|