fork download
  1. #include <stdio.h>
  2. #define MAXLINE 1000 /* максимальный размер вводимой строки */
  3.  
  4. int getline(char line[], int MAXLINE);
  5. void copy(char to[], char from[]);
  6.  
  7. /* печать самой длинной строки */
  8. main()
  9. {
  10. int len; /* длина текущей строки */
  11. int max; /* длина максимальной из просмотренных строк */
  12. char line[MAXLINE]; /* текущая строка */
  13. char longest[MAXLINE]; /* самая длинная строка */
  14.  
  15. max = 0;
  16. while (len = getline(line, MAXLINE)) > 0)
  17. if (len > max) {
  18. max = len;
  19. copy(longest, line);
  20. }
  21. if (max > 0) /* была ли хоть одна строка? */
  22. printf("%s", longest);
  23. return 0;
  24. }
  25.  
  26.  
  27. /* getline: читает строку в s, возвращает длину */
  28. int getline(char s[], int lim)
  29. {
  30. int c, i;
  31.  
  32. for (i = 0; i < lim-1 && (c = getchar()) != EOF && с != '\n'; ++i)
  33. s[i] = c;
  34. if (c == '\n') {
  35. s[i] = c;
  36. ++i;
  37. }
  38. s[i] = '\0';
  39. return i;
  40. }
  41.  
  42. /* copy: копирует из 'from' в 'to'; to достаточно большой */
  43. void copy(char to[], char from[])
  44. {
  45. int i;
  46.  
  47. i = 0;
  48. while ((to[i] = from[i]) != '\0')
  49. ++i;
  50. }
Compilation error #stdin compilation error #stdout 0s 2160KB
stdin
Standard input is empty
compilation info
prog.c:2:17: error: expected ';', ',' or ')' before numeric constant
 #define MAXLINE 1000 /* максимальный размер вводимой строки */
                 ^
prog.c:4:30: note: in expansion of macro 'MAXLINE'
 int getline(char line[], int MAXLINE);
                              ^
prog.c:8:1: warning: return type defaults to 'int' [-Wimplicit-int]
 main()
 ^
prog.c: In function 'main':
prog.c:16:18: warning: implicit declaration of function 'getline' [-Wimplicit-function-declaration]
     while (len = getline(line, MAXLINE)) > 0)
                  ^
prog.c:16:5: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
     while (len = getline(line, MAXLINE)) > 0)
     ^
prog.c:16:42: error: expected expression before '>' token
     while (len = getline(line, MAXLINE)) > 0)
                                          ^
prog.c:16:45: error: expected statement before ')' token
     while (len = getline(line, MAXLINE)) > 0)
                                             ^
prog.c: In function 'getline':
prog.c:32:5: error: stray '\321' in program
     for (i = 0; i < lim-1 && (c = getchar()) != EOF && с != '\n'; ++i)
     ^
prog.c:32:5: error: stray '\201' in program
prog.c:32:59: error: expected expression before '!=' token
     for (i = 0; i < lim-1 && (c = getchar()) != EOF && с != '\n'; ++i)
                                                           ^
stdout
Standard output is empty