我編寫了一個程序,用C編寫一個2D數組,用於打印包含用戶輸入圖形表示的2D表格。我編譯並運行了這個程序,但無論按下Return還是Ctrl + D用於EOF,getchar並沒有像預期的那樣出現在循環中的指令上。我在這裏做錯了什麼?爲什麼不是getchar退出?
int main()
{
/*ignore these comments, they are outdated todo lists*/
/* make vars init here, change for to while */
/* finish printing */
int c;
int i, sec, other;
char ndigit[3][8];
while((c = getchar()) != EOF) {
if (c == '\n' || '\t' || ' ') {
for(i = 0; i < 63; ndigit[1][i] += 1);
;
}
else if (c >= '0' || c <= '9') {
for(sec = 0; sec < 63; ndigit[2][sec] += 1)
;
}
else
for(other = 0; other < 63; ndigit[3][other] += 1)
;
}
for (i = 0; i <= 3; ++i)
for (sec = 0; sec <= 8; sec++)
printf("%s\n", ndigit[i][sec]);
}
1)'c =='\ n'|| '\ t'|| '''總是如此。 2)不改變索引變量。 3)越界。 – BLUEPIXY
爲什麼John Doe的名字?我邀請你用你的真實身份註冊Stack Overflow(以及一些加入你的方式)。 –