首页 > 试题广场 >

修改程序清单8.8中的get_first()函数,使其返回所

[问答题]

修改程序清单8.8中的get_first()函数,使其返回所遇到的第一个非空白字符。在一个简单的程序中测试该函数。

推荐
#include <stdio.h>
#include <ctype.h>
char get_first(void);
int main(void)
{
 char ch;
 while((ch = get_first() ) != EOF)
 {
 putchar(ch);
 }
 return 0;
}
char get_first(void)
{
 int ch;
 while( isspace( ch = getchar() ) );
 while ( getchar() != '\n');
 return ch;
}

发表于 2018-05-05 21:41:37 回复(0)