Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to find integer value for an ascii character

Status
Not open for further replies.

sarav45

Technical User
Sep 25, 2001
5
IN
How to Find Integer value for an ascii Character.
For ex: integer value of Ascii('A') is 65 ,
How to find these value using, kindly help me out
 
Hi,
This should do it.

char ch = 'A';
printf("%d",ch); Pappy
You learn something everyday.
 
Or you could put it in a loop to print ou a charcter set.

#include<stdio.h>

void main()
{
int count;
for(count = 0;count<127;count++)
printf(&quot;%d = %c &quot;,count,count);
}
 
In C/C++, characters are stored internally as binary. On ASCII system, they are stored as ASCII value. Thus, you can do:
Code:
    char ch = 'A';
or
Code:
    char ch = 65;
or
Code:
    char ch = 0x41;

They are all equivalent.

Therefore, taking any value, say 65. You can treat it like any integer value, or ASCII representation of character ¡¥A¡¦. Internally, the program always uses numeric 65. The only time you need to differentiate 65 or 0x41 or ¡¥A¡¦ is when you output the value in some human readable context. In this case, you can use the printf() format specification to ¡¥translate¡¦ how the data needs to be presented.

To output decimal 65:
Code:
    printf(&quot;%d&quot;, ch);
[\code]

To output hex 0x41:
[code]
    printf(&quot;0x%X&quot;, ch);
[\code]

To output character ¡¥A¡¦:
[code]
    printf(&quot;'%c'&quot;, ch);
[\code]

Hope this answer your question.

Shyan
 
here is a hellp full coding for ascii codes.
just press the the key for which you want to see the ascii code. press enter to terminate the program.

void main(void)
{
char ch;
while((ch=getch)!='\r')
{
printf(&quot;%c=%d&quot;,ch,ch);
}
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top