編寫一個程序,從標準輸入讀取幾行輸入。每行輸入都要打印到標準輸出上,前面加上行號。
在編寫這個程序的時候要使這個程序能夠處理的輸入行的長度沒有限制。
#include <stdio.h> #include <stdlib.h> int main() { char ch = '0'; int n = 1; int flag = 1; while (1) { printf("please input the line: "); do { scanf("%c", &ch); if (1 == flag) { flag = 0; printf("%d ", n); } printf("%c", ch); } while (ch != '\n'); flag = 1; n++; } system("pause"); return 0; }