How to input a string in the C programming language?

In C language, you can use the scanf function to input a string. Here is a common way to do it:

#include <stdio.h>

int main() {
    char str[100]; // 假设字符串的最大长度为100

    printf("请输入一个字符串:");
    scanf("%s", str);

    printf("你输入的字符串是:%s\n", str);

    return 0;
}

In the code above, a character array “str” is first defined to store the input string. The scanf function is then used to get the input string, %s is used to read a string (separated by spaces or newlines), and store it in “str”. Lastly, the printf function is used to output the input string to the screen.

bannerAds