[問題] line counting
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
GCC
問題(Question):
執行後,無法測試出是否有newline, tabs, blanks,結果都為0
DOS介面的EOF指令除了control-z 還有?
餵入的資料(Input):
I like programming and surfing on the ptt.
All the output are zeros.
Please help me.
^z
預期的正確結果(Expected Output):
newlines:3
blanks:12
tabs:1
程式碼(Code):(請善用置底文網頁, 記得排版)
int main (void)
{
int c, newlines, blanks, tabs;
int done = 0;
newlines = 0;
blanks = 0;
tabs = 0;
while( c = getchar() != EOF)
{
if ( c == '\n')
newlines++;
if ( c == ' ')
++blanks;
if ( c == '\t')
++tabs;
}
printf ("newlines:%d\nblanks:%d\ntabs:%d\n", newlines, blanks, tabs);
return 0;
}
--
※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 221.120.4.224
※ 文章網址: https://www.ptt.cc/bbs/C_and_CPP/M.1424142439.A.530.html
→
02/17 11:20, , 1F
02/17 11:20, 1F
→
02/17 11:24, , 2F
02/17 11:24, 2F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章