1 //编写一个程序,从标准输入读取几行输入。每行输入都要打印到标准输出上,前面要加上行号。 2 #include <stdio.h> 3 #include <stdlib.h> 4 int main() 5 { 6 int ch; 7 int line; 8 int at_beginning; 9 line = 0; 10 at_beginning = 1; 11 while((ch = getchar()) != EOF){ 12 if(at_beginning == 1){ 13 at_beginning = 0; 14 line += 1; 15 printf("%d",line); 16 } 17 putchar(ch); 18 if(ch == ' ') 19 at_beginning = 1; 20 } 21 system("pause"); 22 return EXIT_SUCCESS; 23 }