edhesive 7.1 question 2
Write a program that asks the user to enter a single character and then outputs the ASCII number of that character. Please follow the same format as in the sample run.

Your program should accept one character only for each ask. Test your code by entering a word, such as paper. What happens? Review any error messages received in CodeSkulptor.

Sample Run 1
Enter a character: %
ASCII #37
Sample Run 2
Enter a character: 8
ASCII #56

Respuesta :

Explanation:

ASCII, abbreviated from American Standard Code for Information Interchange, is a character encoding standard for electronic communication.  Basically, ASCII value is the something which computers understand .

C program that asks the user to enter a single character and then outputs the ASCII number of that character :

#include <stdio.h>

#include <string.h>

int main()  

{  

   char Str[10];

   int i,length;

   printf("Enter the String: ");

   scanf("%s", Str);

   if(strlen(Str) == 1){

       printf(" %c ASCII value is %d",Str[0],Str[0]);

   }

   else{

       printf(" Please enter only single character!! ");

   }

   return 0;  

}