c - 为什么输入字符串不起作用?

标签 c windows linux input

#include <stdio.h>
int main()
{
        char temp[1024];
        if(getchar() != 'y')
        {
                printf("no options\n");
                return 1;
        }
        scanf(temp, "%s");
        printf("%s", temp);
}

我得到如下片段。我只想从用户那里输入两次。但是第一个输入有效,但是第二个输入直接跳过并且 printf("%s", temp); 打印出意外字符。我该如何解决这个问题.. 谢谢

最佳答案

scanf 的第一个参数是格式,第二个是缓冲区。你有它倒退。尝试 scanf( "%s", temp );

关于c - 为什么输入字符串不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1956687/

相关文章:

windows - 版本更新后,SourceTree不会自动刷新

c++ - 使用 CUDA 从 2D 图像编程 3D 模型

c - 在C中将数字写到没有printf的文件中?

c - 未使用的 volatile 变量

node.js - install.js cmd 挂起 - 无法在 Windows 上安装 Electron js npm

android - 混淆器错误 : Expecting class path seperator - not sure where I need to put a path in quotes

linux - 何时检查 EINTR 并重复函数调用?

c++ - std::stringstream 重新分配适用于 Visual Studio 2013,但不适用于 Linux

php - Apache http/https 非 www 到 ww url 重定向

c - GTK/GObject detailed_signal 参数