getchar()函数返回的是int类型,而不是返回char类型。直接使用while(ch = getchar())会导致接收不到结束符号,直到读取到上限才停止。需要显式注明结束标识EOF。
正确的使用方法应当是:
while(ch = getchar()!=EOF)
版权声明:本文为kanbarakun原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。
getchar()函数返回的是int类型,而不是返回char类型。直接使用while(ch = getchar())会导致接收不到结束符号,直到读取到上限才停止。需要显式注明结束标识EOF。
正确的使用方法应当是:
while(ch = getchar()!=EOF)