fork download
  1. #include <stdio.h>
  2. #include <memory.h>
  3.  
  4. #define MAXLINE 1000
  5.  
  6. int getline(char line[], int maxline);
  7. void copy(char to[], char from[]);
  8.  
  9. int main(void){
  10. int c;
  11. int len; /*Äëèíà òåêóùåé ñòðîêè*/
  12. int max; /*Òåêóùàÿ ìàêñèìàëüàíÿ äëèíà*/
  13. char line[MAXLINE]; /*Òåêóùàÿ ââåäåííàÿ ñòðîêà*/
  14. char longest[MAXLINE]; /*Ñàìàÿ äëèííàÿ ñòðîêà*/
  15.  
  16. max = 0;
  17. while((len = getline(line, MAXLINE)) > 0)
  18. if(len > max){
  19. max = len;
  20. copy(line, longest);
  21. }
  22. if(max > 0) printf("%s", longest);
  23.  
  24. return 0;
  25. }
  26.  
  27. int getline(char s[], int lim){
  28. int c, i;
  29.  
  30. for(i = 0; i < lim-1 && (c=getchar()) != EOF && c != '\n'; i++)
  31. s[i] = c;
  32. if(c == '\n'){
  33. s[i] = '\n';
  34. i++;
  35. }
  36. s[i] = '\0';
  37. return i;
  38. }
  39.  
  40. void copy(char from[], char to[]){
  41. int i;
  42.  
  43. i = 0;
  44. while((to[i] = from[i]) != '\0')
  45. i++;
  46. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
abc
abcd
abcdef
abc def ghi
compilation info
prog.c:6:5: error: conflicting types for 'getline'
 int getline(char line[], int maxline);
     ^
In file included from prog.c:1:0:
/usr/include/stdio.h:678:20: note: previous declaration of 'getline' was here
 extern _IO_ssize_t getline (char **__restrict __lineptr,
                    ^
prog.c: In function 'main':
prog.c:10:6: warning: unused variable 'c' [-Wunused-variable]
  int c;
      ^
prog.c: At top level:
prog.c:27:5: error: conflicting types for 'getline'
 int getline(char s[], int lim){
     ^
In file included from prog.c:1:0:
/usr/include/stdio.h:678:20: note: previous declaration of 'getline' was here
 extern _IO_ssize_t getline (char **__restrict __lineptr,
                    ^
stdout
Standard output is empty