[問題] getchar() 和 putchar()
程式一的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
推
10/25 17:08, , 1F
10/25 17:08, 1F
討論串 (同標題文章)
以下文章回應了本文:
完整討論串 (本文為第 1 之 2 篇):
Programming 近期熱門文章
PTT數位生活區 即時熱門文章