fork(2) download
  1. #include <stdio.h>
  2.  
  3. #define MAXLINE 1000;
  4.  
  5. int max;
  6. char line[MAXLINE];
  7. char longest[MAXLINE];
  8.  
  9.  
  10. int geline(void);
  11. void copy(void);
  12.  
  13. int main() {
  14. int len;
  15. extern int max;
  16. extern char longest[];
  17. max = 0;
  18.  
  19. while ((len = getline()) >= 0)
  20. if (len > max) {
  21. max = len;
  22. copy();
  23. }
  24. if (max > 0)
  25. printf("%s", longest);
  26. return 0;
  27. }
  28.  
  29.  
  30. int getline (void) {
  31. int c, i;
  32. extern char line[];
  33. for (i = 0; i < MAXLINE-1 && (c = getchar()) !+ EOF && c != '\n'; ++i)
  34. line[i] = c;
  35. if (c == '\n') {
  36. line[i] = c;
  37. ++i;
  38. }
  39. line[i] = '\0';
  40.  
  41. return i;
  42. }
  43.  
  44. void copy(void) {
  45. int i;
  46. extern char line[], longest[];
  47.  
  48. i = 0;
  49. while ((longest[i] = line[i]) != '\0' ) ++i;
  50. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:3:21: error: expected ‘]’ before ‘;’ token
 #define MAXLINE 1000;
                     ^
prog.c:6:11: note: in expansion of macro ‘MAXLINE’
 char line[MAXLINE];
           ^~~~~~~
prog.c:3:21: error: expected ‘]’ before ‘;’ token
 #define MAXLINE 1000;
                     ^
prog.c:7:14: note: in expansion of macro ‘MAXLINE’
 char longest[MAXLINE];
              ^~~~~~~
prog.c: In function ‘main’:
prog.c:19:19: warning: implicit declaration of function ‘getline’ [-Wimplicit-function-declaration]
     while ((len = getline()) >= 0)
                   ^~~~~~~
prog.c: In function ‘getline’:
prog.c:33:31: warning: value computed is not used [-Wunused-value]
     for (i = 0; i < MAXLINE-1 && (c = getchar()) !+ EOF && c != '\n'; ++i)
                            ~~~^~~~~~~~~~~~~~~~~~
prog.c:33:50: error: expected ‘)’ before ‘!’ token
     for (i = 0; i < MAXLINE-1 && (c = getchar()) !+ EOF && c != '\n'; ++i)
                                                  ^
stdout
Standard output is empty