[问题] 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