依然是看答案
1 #include <stdio.h> 2 #define MAXLINE 1000 //允许输入行的最大长度 3 #define LONGLINE 80 4 5 int getline(char line[], int maxline); 6 7 // print lines longer than LONGLINE 8 main() 9 { 10 int len; 11 char line[MAXLINE]; 12 13 while((len - getline(line, MAXLINE)) > 0) 14 if(len > LONGLINE) 15 printf("%S", line); 16 return 0; 17 18 } 19 20 int getline(char s[], int lim) 21 { 22 int c, i, j; 23 j = 0; 24 for(i = 0; (c = getchar()) != EOF && c != ' '; ++i) 25 if(i < lim - 2) 26 { 27 s[j] = c; 28 ++j; 29 } 30 if(c == ' '){ 31 s[j] = c; 32 ++j; 33 ++i; 34 } 35 s[j] = '