Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Printing chars and their ASCII-code in C

Tags:

c

printf

How do I print a char and its equivalent ASCII value in C?

like image 977
Chris_45 Avatar asked Sep 24 '09 15:09

Chris_45


People also ask

What is ASCII code in C?

In C programming, a character variable holds ASCII value (an integer number between 0 and 127) rather than that character itself. This integer value is the ASCII code of the character. For example, the ASCII value of 'A' is 65.

What is the ASCII value of A to Z?

Below are the implementation of both methods: Using ASCII values: ASCII value of uppercase alphabets – 65 to 90. ASCII value of lowercase alphabets – 97 to 122.


1 Answers

This prints out all ASCII values:

int main() {     int i;     i=0;     do     {         printf("%d %c \n",i,i);         i++;     }     while(i<=255);     return 0; } 

and this prints out the ASCII value for a given character:

int main() {     int e;     char ch;     clrscr();     printf("\n Enter a character : ");     scanf("%c",&ch);     e=ch;     printf("\n The ASCII value of the character is : %d",e);     getch();     return 0; } 
like image 131
ennuikiller Avatar answered Sep 30 '22 21:09

ennuikiller