下面的程序,不停地从控制台读入一行数据并回显,直到遇到空行结束。
代码如下:
#include <stdio.h>
int main(void) {
char c;
int count;
for(;;){
count=0;
printf("Please enter a line [blank line to terminate]> ");
do{
c=getchar();
putchar(c);
count++;
}while (c!='\n');
if(count==1) break;
}
}
可能的输出结果:
Please enter a line [blank line to terminate]> 123456
123456
Please enter a line [blank line to terminate]> abcxyz
abcxyz
Please enter a line [blank line to terminate] > 城东书院
城东书院
Please enter a line [blank line to terminate]> game over
game over
Please enter a line [blank line to terminate]>
Press any key to continue