How to input characters in the C language?

In the C language, the scanf function can be used to input characters.

For example, the following code demonstrates how to input a character and output it:

#include <stdio.h>

int main() {
    char ch;

    printf("请输入一个字符:");
    scanf("%c", &ch);

    printf("您输入的字符是:%c\n", ch);

    return 0;
}

Running the program will prompt the user to enter a character, and then display the inputted character on the screen.

bannerAds