0

我正在使用 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>
4

1 回答 1

0

<"file name"意思是从一个名为“文件名”的文件中获取输入,所以当你运行它时,./a.out<"file name"你告诉 shell 使用源文件作为执行程序的输入。只是运行它./a.out

于 2013-10-11T03:44:17.630 回答