[問題] 利用scanf讀string的問題
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
GCC
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
問題(Question):
使用while(scanf("%s%s", string1,string2) != EOF)
想要一次讀入兩個string
但似乎都不成功,用print印出來都會變成string2的一部分
例如輸入3400 & 3999
printf string1 & string2 會跑出 999 & 3999
餵入的資料(Input):
ex.
3400 3999
預期的正確結果(Expected Output):
3400
3999
錯誤結果(Wrong Output):
999
3999
程式碼(Code):(請善用置底文網頁, 記得排版)
int main(void)
{
char string1[] = "",string2[] = "";
while (scanf("%s %s", string1,string2) != EOF){
printf("%s\n", string1);
printf("%s\n", string2);
}
return 0;
}
補充說明(Supplement):
我剛學C不久,對C並不是很熟悉
麻煩版友幫我解惑
謝謝!
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 114.36.163.21
→
10/31 00:32, , 1F
10/31 00:32, 1F
→
10/31 00:33, , 2F
10/31 00:33, 2F
→
10/31 00:39, , 3F
10/31 00:39, 3F
→
10/31 00:41, , 4F
10/31 00:41, 4F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章