一行一行读取输入行,直至到达文件尾。算出输入行的长度,输出最大行

 1 #include <stdio.h>
 2 #include <stdlib.h>
 3 #include <string.h>
 4 int main()
 5 {
 6     int i = 0;
 7     char ch;
 8     int max = 0;
 9     char str1[1000];
10     char str2[1000];
11     memset(str1,0,1000);
12     memset(str2,0,1000);
13     
14     while((ch = getchar()) != EOF)
15     {
16         if(ch != '
')
17         {
18             str1[i++] = ch;
19             continue;
20         }
21         str1[i] = '';
22         if(i > max)
23         {
24             max = i;
25             strcpy(str2,str1);
26         }
27         i = 0;
28     }
29     puts(str2);
30     system("pause");
31     return 0;
32 }

19行  continue  用的巧妙!!

原文地址:https://www.cnblogs.com/joyclub/p/4479707.html