2013-10-10 137 views
0

我使用OSX終端來編譯和運行我的C代碼。OSX終端不接受來自簡單程序的輸入

由於某種原因,每當我想從使用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> 
+0

適用於我的10.8 ... – Eugene

+0

您是如何執行該程序的? –

+0

gcc「文件名」 ./a.out <「文件名」 – rlima1877

回答

0

<"file name"意味着需要從一個名爲「文件名」文件輸入,所以當你與./a.out<"file name"運行它你告訴外殼使用源文件作爲執行程序的輸入。改爲使用./a.out代替它。

相關問題