whats wrong with it.it does not give any ascii code.please tell me simple program.Code:#include <stdio.h> #include <conio.h> void main() { int x; printf("Enter a decimal number\n",x); printf("The character is %c\n",x); getch (); }
whats wrong with it.it does not give any ascii code.please tell me simple program.Code:#include <stdio.h> #include <conio.h> void main() { int x; printf("Enter a decimal number\n",x); printf("The character is %c\n",x); getch (); }
Are you familiar with the concept of a manual? If not, I suggest you look it up. Here, straight from the printf manual, headed under 'conversion specifier', 'c':
... the int argument is converted to an unsigned char, and the resulting character is written.
iMalc: Your compiler doesn't accept misspellings and bad syntax, so why should we?
justin777: I have no idea what you are talking about sorry, I use a laptop and there is no ascii eject or something
What decimal numbers are you entering? try 65 which should print A or 49 which should print 1
Look at an ASCII code chart... *not all decimal values lead to printable characters!*
For example if you entered 7 ... your computer should beep at you (ascii bell character)
The ASCII code was originally created to standardize communications between teletype stations on the old "Telegram" network... It thus includes a number of control characters such as Carriage Return, End of Page, Line Feed, etc. that were used to control the mechanism itself.
Teleprinter - Wikipedia, the free encyclopedia
Last edited by CommonTater; 11-06-2011 at 10:31 AM.
my above program is returning me the same value every time.it prints unknown character every time and on each value i give.whats wrong with my program?
Well first of all you're not asking for input anywhere...
Code:#include <stdio.h> #include <conio.h> void main() { int x = 0; printf("Enter a decimal number\n",x); // this does not read the keyboard // get number from user here... printf("The character is %c\n",x); getch (); }
Lose lines 10 and 11 ...
in line 12... print x, not ch;
As it is... the character printed will not accurately represent the value entered.
ok thanks.done.
Printing an int with %c is wrong and probably wont work on a big-endian machine. It really should be casted to char first.
My homepage
Advice: Take only as directed - If symptoms persist, please see your debugger
Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"