[英]C stdin reads file infinitely
我有一個基本的C程序,需要從stdin讀取輸入。 首先,它使用以下命令從輸入文件中讀取
./Program <input
然后循環遍歷,直到沒有更多
while(scanf("%s",command)!=EOF){
printf("%s\n",command);
}
之后,我需要再次從鍵盤上進行讀取,但是它繼續無限發送以垃圾郵件讀取輸入文件中的最后一行,而不是讓我使用鍵盤進行輸入。
while(1){
scanf("%s",command);
if(!strcasecmp(command,"exit"))
exitProg();
else if(!strcasecmp(command,"help"))
helpMess();
else
printf("Command \"%s\" not recognized, use command \"help\" for a list.\n",command);
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.