fork download
  1. #include <stdio.h>
  2. #include <memory.h>
  3.  
  4. #define MAXLINE 1000
  5.  
  6. int xgetline(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 = xgetline(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 xgetline(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. }
Success #stdin #stdout 0s 2056KB
stdin
abc
abcd
abcdef
abc def ghi
                x
xxxxxxxxxxxxxxxxxxxx
stdout
xxxxxxxxxxxxxxxxxxxx