fork(3) download
  1. #include <stdio.h>
  2. #include <memory.h>
  3.  
  4. #define MAXLINE 100
  5.  
  6. int xgetline(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 = xgetline(line, MAXLINE)) > 0)
  18. if(len > max){
  19. max = len;
  20. copy(line, longest);
  21. }
  22. if(max > 0) printf("%s\n", longest);
  23. if(max > 0) printf("%d", max);
  24.  
  25. return 0;
  26. }
  27.  
  28. int xgetline(char s[], int lim){
  29. int c, i;
  30.  
  31. for(i = 0; i < lim-1 && (c=getchar()) != EOF && c != '\n'; i++)
  32. s[i] = c;
  33. if(c == '\n'){
  34. s[i] = '\n';
  35. i++;
  36. }
  37. s[i] = '\0';
  38. return i;
  39. }
  40.  
  41. void copy(char from[], char to[]){
  42. int i;
  43.  
  44. i = 0;
  45. while((to[i] = from[i]) != '\0')
  46. i++;
  47. }
Success #stdin #stdout 0s 2012KB
stdin
abc
abcd
abcde
abcdef
stdout
abcde

6