相关疑难解决方法(0)

从空间字符输入读取字符串?

我正在使用Ubuntu,我也使用Geany和CodeBlock作为我的IDE.我正在尝试做的是读取一个字符串(如"Barack Obama")并将其放在一个变量中:

#include <stdio.h>

int main(void)
{
    char name[100];

    printf("Enter your name: ");
    scanf("%s", name);
    printf("Your Name is: %s", name);

    return 0;
}
Run Code Online (Sandbox Code Playgroud)

输出:

Enter your name: Barack Obama
Your Name is: Barack
Run Code Online (Sandbox Code Playgroud)

如何让程序读取整个名称?

c string whitespace input scanf

93
推荐指数
5
解决办法
50万
查看次数

标签 统计

c ×1

input ×1

scanf ×1

string ×1

whitespace ×1