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: Christian S. <sm...@xs...> - 2003-05-26 00:51:03
|
Hi,
I'm a beginner too :)
As far as I know, in this context ( the code I forwarded) it's needed as the
stdio functions getc ( ) and getchar ( ) return the interger value of the
character. However its easy to convert them back to an ascii character like
when using the function printf (). Ooh and I havn't reached the bit on
strings yet so its possible you are right but the author just wants to keep
it simple for now and use intergers. Everything is a number on a computer
(as the author once said).
example
#include <stdio.h>
main ( )
{
int c; /* Declare interger */
c = getchar ( ); /* reads your keyboard for pressed keys and return the
ascii value */
printf ("You pressed %c which ascii is %d.\n",c,c);
return 0;
}
BTW: You forgot to CC the list and I and Papa Smurf are the same people :).
Its just that my reply is setup that way.
> -----Original Message-----
> From: Keats [mailto:ke...@ih...]
> Sent: maandag 26 mei 2003 2:39
> To: Christian Schmidt
> Subject: Re: [Dev-C++] Why is this code not doing what it should do?
> (simple example code from book)
>
>
> Hi,
>
> I'm a java programmer who is just about to learn C/C++ (just finding the
> time is the hard part :( ) but to me there is another error in the code,
> apart from the one Papa Smurf found. You declared 'c' as a int,
> shouldn't this be a declared as a char or string or are these operations
> allowed in C/C++?
>
> Matt
>
>
>
|