看板 Programming 關於我們 聯絡資訊
程式一的putchar()是一次把1234印出 而為什麼程式二的putchar()不是一次印出1234反而一次只印出一個字元 今天一直在confuse這個問題 麻煩大大了 ><" Program 1 #include <stdio.h> /* copy input to output */ int main(void) { int c; while((c = getchar()) != EOF) putchar(c); return 0; } 輸入1234 Ans:1234 Program 2 #include <stdio.h> /* copy input to output */ int main(void) { int c,nc; nc = 0; while((c = getchar()) != EOF){ ++nc; /* nc是我用來測試執行for loop的次數 printf("%d\n",nc); putchar(c); printf("\n"); } return 0; } 輸入1234 Ans: 1 1 2 2 3 3 4 4 5 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.117.176.164
pupucar:程式一也是一次印一個阿 只是他沒換行而已 61.231.55.121 10/25 17:08