[問題] scanf 測資結尾
問題(Question):
測資的結尾並沒有'\n'
但用gdb跑的時候,gdb顯示c最後吃進了一個'n'
為什麼最後會吃進'\n'呢@@?
先感謝好心人幫忙解惑了 <(_ _)>
餵入的資料(Input):
asdf
預期的正確結果(Expected Output):
-----------
1 a
1 s
1 d
1 f
-----------
錯誤結果(Wrong Output):
-----------
1 a
1 s
1 d
1 f
1
-----------
程式碼(Code):(請善用置底文網頁, 記得排版)
#include<stdio.h>
int main(){
int t;
char c;
while((t=scanf("%c",&c))==1)
{
printf("%d %c\n",t,c);
}
return 0;
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 140.119.204.110
※ 編輯: otomoyox 來自: 140.119.204.110 (12/09 10:23)
推
12/09 10:28, , 1F
12/09 10:28, 1F
→
12/09 10:39, , 2F
12/09 10:39, 2F
推
12/09 11:46, , 3F
12/09 11:46, 3F
→
12/09 11:51, , 4F
12/09 11:51, 4F
→
12/09 12:44, , 5F
12/09 12:44, 5F
→
12/09 17:24, , 6F
12/09 17:24, 6F
→
12/09 18:36, , 7F
12/09 18:36, 7F
→
12/10 14:04, , 8F
12/10 14:04, 8F
→
12/13 15:57, , 9F
12/13 15:57, 9F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章