C Online Compiler
Example: ASCII Code from User Input in C
C
C++
C#
Java
Python
PHP
main.c
STDIN
Run
// ASCII Code from User Input #include <stdio.h> int main() { // Step 1: Declare a character variable to store user input. char inputChar; // Step 2: Prompt the user to enter a character. printf("Enter a character: "); // Step 3: Read the character from the user. // Use " %c" to consume any leftover newline character from previous inputs, // though for a fresh input, "%c" is often sufficient. scanf(" %c", &inputChar); // Step 4: Print the character and its ASCII value. printf("The ASCII value of '%c' is %d\n", inputChar, inputChar); return 0; }
Output
Clear
ADVERTISEMENTS