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.  
  17. while (len = getline(line, MAXLINE))0)
  18. if (len › max) {
  19. max = len;
  20. copy(longest, line);
  21. }
  22. if (max › 0) /* была ли хоть одна строка? */
  23. printf("%s", longest);
  24. return 0;
  25. }
  26.  
  27. /* getline: читает строку в s, возвращает длину */
  28. int getline(char s[], int lim)
  29. {
  30. int c, i;
  31. for (i = 0; i ‹ lim-1 && (c = getchar()) != EOF && с != '\n'; ++i)
  32. s[i] = c;
  33. if (c == '\n') {
  34. s[i] = c;
  35. ++i;
  36. }
  37. s[i] = '\0';
  38. return i;
  39. }
  40.  
  41. /* copy: копирует из 'from' в 'to'; to достаточно большой */
  42. void copy(char to[], char from[])
  43. {
  44. int i;
  45. i = 0;
  46. while ((to[i] = from[i]) != '\0')
  47. ++i;
  48. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:1:10: error: #include expects "FILENAME" or <FILENAME>
 #include ‹stdio.h›
          ^
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:17:15: warning: implicit declaration of function ‘getline’ [-Wimplicit-function-declaration]
  while (len = getline(line, MAXLINE)) › 0)
               ^~~~~~~
prog.c:17:2: warning: suggest parentheses around assignment used as truth value [-Wparentheses]
  while (len = getline(line, MAXLINE)) › 0)
  ^~~~~
prog.c:17:39: error: stray ‘\342’ in program
  while (len = getline(line, MAXLINE)) › 0)
                                       ^
prog.c:17:40: error: stray ‘\200’ in program
  while (len = getline(line, MAXLINE)) › 0)
                                        ^
prog.c:17:41: error: stray ‘\272’ in program
  while (len = getline(line, MAXLINE)) › 0)
                                         ^
prog.c:17:43: warning: statement with no effect [-Wunused-value]
  while (len = getline(line, MAXLINE)) › 0)
                                           ^
prog.c:17:44: error: expected ‘;’ before ‘)’ token
  while (len = getline(line, MAXLINE)) › 0)
                                            ^
prog.c:17:2: warning: this ‘while’ clause does not guard... [-Wmisleading-indentation]
  while (len = getline(line, MAXLINE)) › 0)
  ^~~~~
prog.c:17:44: note: ...this statement, but the latter is misleadingly indented as if it is guarded by the ‘while’
  while (len = getline(line, MAXLINE)) › 0)
                                            ^
prog.c:17:44: error: expected statement before ‘)’ token
prog.c:18:11: error: stray ‘\342’ in program
   if (len › max) {
           ^
prog.c:18:12: error: stray ‘\200’ in program
   if (len › max) {
            ^
prog.c:18:13: error: stray ‘\272’ in program
   if (len › max) {
             ^
prog.c:18:15: error: expected ‘)’ before ‘max’
   if (len › max) {
               ^~~
prog.c:22:10: error: stray ‘\342’ in program
  if (max › 0) /* была ли хоть одна строка? */
          ^
prog.c:22:11: error: stray ‘\200’ in program
  if (max › 0) /* была ли хоть одна строка? */
           ^
prog.c:22:12: error: stray ‘\272’ in program
  if (max › 0) /* была ли хоть одна строка? */
            ^
prog.c:22:14: error: expected ‘)’ before numeric constant
  if (max › 0) /* была ли хоть одна строка? */
              ^
prog.c:23:3: warning: implicit declaration of function ‘printf’ [-Wimplicit-function-declaration]
   printf("%s", longest);
   ^~~~~~
prog.c:23:3: warning: incompatible implicit declaration of built-in function ‘printf’
prog.c:23:3: note: include ‘<stdio.h>’ or provide a declaration of ‘printf’
prog.c: In function ‘getline’:
prog.c:31:16: error: stray ‘\342’ in program
  for (i = 0; i ‹ lim-1 && (c = getchar()) != EOF && с != '\n'; ++i)
                ^
prog.c:31:17: error: stray ‘\200’ in program
  for (i = 0; i ‹ lim-1 && (c = getchar()) != EOF && с != '\n'; ++i)
                 ^
prog.c:31:18: error: stray ‘\271’ in program
  for (i = 0; i ‹ lim-1 && (c = getchar()) != EOF && с != '\n'; ++i)
                  ^
prog.c:31:20: error: expected ‘;’ before ‘lim’
  for (i = 0; i ‹ lim-1 && (c = getchar()) != EOF && с != '\n'; ++i)
                    ^~~
prog.c:31:55: error: stray ‘\321’ in program
  for (i = 0; i ‹ lim-1 && (c = getchar()) != EOF && с != '\n'; ++i)
                                                       ^
prog.c:31:56: error: stray ‘\201’ in program
  for (i = 0; i ‹ lim-1 && (c = getchar()) != EOF && с != '\n'; ++i)
                                                        ^
stdout
Standard output is empty