[問題] line counting

作者: linada1230 (linada)   2015-02-17 11:07:17
開發平台(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;
}
作者: descent (「雄辯是銀,沉默是金」)   2015-02-17 11:20:00
c = getchar() => (c = getchar()) 加上括弧
作者: linada1230 (linada)   2015-02-17 11:24:00
感謝!!!

Links booklink

Contact Us: admin [ a t ] ucptt.com