| | |
How to find ASCII value of character in c
![]() |
Here is sample code, which demonstrates on how to get a the ASCII code for the entered char.
NOTE: This is limitedto quite a lot of stuff. You coud place some error checking to make it more perfect.
And you can always find a ascii char chart on the net. Here is link for one which is found ASCII.
ssharish
C Syntax (Toggle Plain Text)
#include <stdio.h> #define TRUE 1 void clear_buffer( void ) { int ch; while( ( ch = getchar() ) != '\n' && ch != EOF ); } int main() { unsigned int ch; while( TRUE ) { printf("\nsingle char please - " ); ch = getchar(); clear_buffer(); printf("%c - %d", ch, ch ); } } /* my output single char please - a a - 97 single char please - s s - 115 single char please - d d - 100 single char please - */
NOTE: This is limitedto quite a lot of stuff. You coud place some error checking to make it more perfect.
And you can always find a ascii char chart on the net. Here is link for one which is found ASCII.
ssharish
Last edited by ssharish2005; Jun 27th, 2008 at 1:06 pm.
In C, you can use the char data type just like a number and it will automatically convert it to the ASCII value. Here's a minimal example:
myNum would have the value 97 in it.
c Syntax (Toggle Plain Text)
int myNum = 'a';
myNum would have the value 97 in it.
•
•
Join Date: May 2008
Posts: 38
Reputation:
Solved Threads: 2
C Syntax (Toggle Plain Text)
#include<stdio.h> void main (void) { char x; printf("\nEnter a Character : "); x = getchar(); printf("\nThe ASCII for Char is: %d",x); }
•
•
Join Date: May 2008
Posts: 38
Reputation:
Solved Threads: 2
C Syntax (Toggle Plain Text)
#include<stdio.h> int main () { char x; printf("\nEnter a Character : "); x = getchar(); printf("\nThe ASCII for Char is: %d",x); return 0;/*** was avoiding this line ****/ }
Last edited by Software guy; Jul 9th, 2008 at 12:19 pm.
•
•
•
•
#include<stdio.h> int main () { char x; printf("\nEnter a Character : "); x = getchar(); printf("\nThe ASCII for Char is: %d",x); return 0;/*** was avoiding this line ****/ }
getchar returns an int , x should be an int . This is done to handle EOF . "One of the methods used by statists to destroy capitalism consists in establishing controls that tie a given industry hand and foot, making it unable to solve its problems, then declaring that freedom has failed and stronger controls are necessary." --Ayn Rand
![]() |
Similar Threads
- numeric TextBox (VB.NET)
- ArrayOutofBounds (Java)
- Pls help :Find first non-repeated char in a string (C++)
- random (C++)
- Codes FOr VGA/SVGA using ports and not interrupts (Assembly)
- HELP - Printing Integers (Assembly)
- GetKey via Interrupt or I/O (Assembly)
- String to integer to ascii (C)
- Array troubles? (C++)
- 4Q i cannot find in my book (Java)
Other Threads in the C Forum
- Previous Thread: any tutorial web site
- Next Thread: help me with this code
| Thread Tools | Search this Thread |
#include adobe ansi api array asterisks binarysearch changingto char character cm copyimagefile cprogramme creafecopyofanytypeoffileinc createcopyoffile csyntax database directory dynamic execv feet fgets file fork forloop frequency function getlasterror givemetehcodez global grade graphics gtkgcurlcompiling hacking hardware highest histogram i/o include incrementoperators infiniteloop input interest kernel keyboard kilometer license linked linkedlist linux linuxsegmentationfault list locate logical_drives looping loopinsideloop. lowest match matrix meter microsoft motherboard mqqueue mysql number odf opensource owf pattern pdf performance pointer posix probleminc process program programming radix recursion recv repetition research reversing scanf segmentationfault sequential shape socket socketprograming standard string systemcall threads turboc unix user voidmain() wab windows.h windowsapi






