Advertisement
Guest User

Untitled

a guest
Sep 1st, 2015
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. #include <stdio.h>
  2. #define MAXLINE 1000
  3.  
  4. int getline(char line[], int maxline);
  5. void copy(char to[], char from[]);
  6.  
  7. int main()
  8. {
  9. int len;
  10. int max;
  11. char line[MAXLINE];
  12. char longest[MAXLINE];
  13.  
  14. max = 0;
  15. while((len = getline(line, MAXLINE)) > 0)
  16. if (len > max) {
  17. max = len;
  18. copy(longest, line);
  19. }
  20. if (max > 0)
  21. printf("%s", longest);
  22. return(0);
  23. }
  24.  
  25. int getline(char s[], int lim)
  26. {
  27. int c, i;
  28.  
  29. for (i=0; i<lim-1 && (c = getchar())!=EOF && c!='n'; ++i)
  30. s[i] = c;
  31. if (c == 'n') {
  32. s[i] = c;
  33. }
  34. s[i] = '';
  35. return(i);
  36. }
  37.  
  38. void copy(char to[], char from[])
  39. {
  40. int i;
  41.  
  42. i = 0;
  43. while ((to[i] = from[i]) != '')
  44. ++i;
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement