【问题标题】:OSX terminal not accepting input from simple programOSX 终端不接受来自简单程序的输入
【发布时间】:2013-10-10 23:15:00
【问题描述】:

我正在使用 OSX 终端来编译和运行我的 C 代码。

出于某种原因,每当我想使用 OSX 终端从程序中获取输入,而不是允许我输入输入(例如字符串)时,终端实际上​​将我的代码的第一行作为输入。奇怪!

我将展示我的简单程序以及输出的外观。

#include <stdio.h>
#include <stdlib.h>
#include <strings.h>

int main(void){


    char text[100];


  printf("Type a text: \n");

    gets(text);

    printf("%s\n",text);

    return 0;

}

我的终端输出:

Type a text: 
warning: this program uses gets(), which is unsafe.
#include <stdio.h>

【问题讨论】:

  • 你是如何执行程序的?
  • gcc "文件名" ./a.out

标签: macos input terminal


【解决方案1】:

&lt;"file name" 表示从名为“文件名”的文件中获取输入,因此当您使用./a.out&lt;"file name" 运行它时,您是在告诉 shell 使用源文件作为执行程序的输入。只需使用 ./a.out 运行它。

【讨论】:

    猜你喜欢
    • 2013-10-23
    • 1970-01-01
    • 2016-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-06-20
    • 2019-02-17
    • 1970-01-01
    相关资源
    最近更新 更多