[問題] 關於輸入字元問題
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
linux
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
無
問題(Question):
空格一直無法計算數目
餵入的資料(Input):
隨便的字元
預期的正確結果(Expected Output):
qwqw
the enter number is: 1
qwqdkfjsdl
the tab number is: 1
the tab number is: 2
the enter number is: 2
ps:尚未加入空格的計算
錯誤結果(Wrong Output):
abc.c: In function a€maina€:
abc.c:22: error: expected a€;a€ before a€printfa€
ps:這是加上空格計算的錯誤
程式碼(Code):(請善用置底文網頁, 記得排版)
#include <stdio.h>
main()
{
int c ,nl,nt,np; //nt=0,np= 0;
nl= 0;
nt= 0;
np= 0;
while((c= getchar())!=EOF)
{
if(c=='\n')
{ ++nl;
printf("\nthe enter number is: %d\n",nl);
}
if(c=='\t')
{
++nt;
printf("\nthe tab number is: %d\n",nt);
}
if(c==' ')
{
++np
printf("\nthe space number is:%d\n",np);
}
}
}
補充說明(Supplement):
末學我做的是K&R的練習題,我將我寫的對照解答,邏輯運算過程都差不多
除了printf的方式不太一樣之外
但獨獨空格部分一直用不出來,找了好久還是找不出來
請各位前被指點迷津
感謝
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 59.120.3.96
推
05/07 15:38, , 1F
05/07 15:38, 1F
→
05/07 15:42, , 2F
05/07 15:42, 2F