fork(1) download
  1. #include <stdio.h>
  2. #include <memory.h>
  3.  
  4. #define MAXLINE 5
  5.  
  6. int get_line(char line[], int maxline);
  7. void copy(char to[], char from[]);
  8.  
  9. int main(int argc, char **argv){
  10. int c;
  11. int len; /*Äëèíà òåêóùåé ñòðîêè*/
  12. int max; /*Òåêóùàÿ ìàêñèìàëüàíÿ äëèíà*/
  13. char line[MAXLINE]; /*Òåêóùàÿ ââåäåííàÿ ñòðîêà*/
  14. char longest[MAXLINE]; /*Ñàìàÿ äëèííàÿ ñòðîêà*/
  15.  
  16. max = 0;
  17. while((len = get_line(line, MAXLINE)) > 0){
  18. if(line[len-1] != '\n')
  19. while((c = getchar()) != EOF && c != '\n')
  20. len++;
  21. if(len > max){
  22. max = len;
  23. copy(line, longest);
  24. }
  25. }
  26. if(max > 0) printf("%s\n", longest);
  27. if(max > 0) printf("%d", max);
  28.  
  29. return 0;
  30. }
  31.  
  32. int get_line(char s[], int lim){
  33. int c, i;
  34.  
  35. for(i = 0; i < lim-1 && (c=getchar()) != EOF && c != '\n'; i++)
  36. s[i] = c;
  37. if(c == '\n'){
  38. s[i] = '\n';
  39. i++;
  40. }
  41. s[i] = '\0';
  42. return i;
  43. }
  44.  
  45. void copy(char from[], char to[]){
  46. int i;
  47.  
  48. i = 0;
  49. while((to[i] = from[i]) != '\0')
  50. i++;
  51. }
Success #stdin #stdout 0s 2056KB
stdin
     ▲
    ▲ ▲
   ▲ ▲ ▲
  ▲ ▲ ▲ ▲
 ▲ ▲ ▲ ▲ ▲
▲ ▲ ▲ ▲ ▲ ▲
stdout
▲�
28