相关疑难解决方法(0)

如何读取未知长度的输入字符串?

如果我不知道这个词有多长,我就不会写char m[6];,
这个词的长度可能是十到二十个.如何使用scanf键盘输入?

#include <stdio.h>
int main(void)
{
    char  m[6];
    printf("please input a string with length=5\n");
    scanf("%s",&m);
    printf("this is the string: %s\n", m);
    return 0;
}
Run Code Online (Sandbox Code Playgroud)

请输入一个lenght = 5 的字符串
你好
这是字符串:hello

c scanf

57
推荐指数
5
解决办法
13万
查看次数

标签 统计

c ×1

scanf ×1