fork 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 getline(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. }
Success #stdin #stdout 0s 9424KB
stdin
a
abc
this is the longest line
aaaaaaaa
aaaa
aa
stdout
this is the longest line