0
打印結果,我有這樣的代碼:C,而環停在EOF但在一個新的生產線
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
char vector[5][100];
int i = 0;
int aux = 0;
while (i <5 && scanf("%s", vector[i])!=EOF)
{
i++;
aux+= 1;
}
for (i=0;i<aux;i++)
{
printf("%s\n", vector[i]);
}
return 0;
}
它做我想要什麼,但我仍然有一些問題。
第一個問題:(解決)
如果我輸入a b c d e f g h i j
輸出是:
a b c d e f g h i ja
b
c
d
e
願意我可以做文我按CTRL-d它打印,在第一輸出新隊? 事情是這樣的:
a b c d e f g h i j
a
b
c
d
e
第二個問題:
如果我輸入a b c
爲什麼我必須按多於一次CTRL-d打印輸出?
問候,
FAvolas
那是那麼容易。謝謝。那我的第二個問題呢? – Favolas 2011-04-04 08:10:15
@Favolas:看到[這裏](http://stackoverflow.com/questions/5406588/eof-reading-c-c/5406652#5406652) – 2011-04-04 08:41:51
對不起,我錯過了第二部分。但是約翰做到了;)。歡呼聲 – CoolStraw 2011-04-04 09:53:54