Advertisement
Guest User

Untitled

a guest
May 30th, 2016
200
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 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. main () {
  8.  
  9. int len;
  10. int max;
  11. char line[MAXLINE];
  12. char longest[MAXLINE];
  13.  
  14. max = 0;
  15.  
  16. while ((len = getline(line, MAXLINE)) > 0) {
  17.  
  18. if(len > max) {
  19.  
  20. max = len;
  21. copy(longest, line);
  22.  
  23. }
  24.  
  25. }
  26.  
  27. if(max > 0) printf("%s", longest);
  28.  
  29. return 0;
  30. }
  31.  
  32. int getline (char line[], int limit) {
  33.  
  34. int i, c;
  35.  
  36. for (i = 0; i < limit - 1 && (c = getchar()) != EOF && c != 'n'; i++) line[i] = c;
  37.  
  38. if (c == 'n') {
  39.  
  40. line[i] = c;
  41. i++;
  42.  
  43. }
  44.  
  45. line[i] = '';
  46.  
  47. return i;
  48. }
  49.  
  50. void copy(char to[], char from[]) {
  51.  
  52. int i;
  53.  
  54. i = 0;
  55. while((to[i] = from[i]) != '')
  56. i++;
  57. }
  58.  
  59. #include <stdio.h>
  60. #include <stdlib.h>
  61. #include <string.h>
  62. #define MAX_LINE 1000
  63.  
  64. int main()
  65. {
  66. int ch; //char input
  67. int length; //length of the line
  68. int max=0; //length of the longest line
  69. int j=0;
  70. int i=0;
  71. char line[MAX_LINE]; //line input
  72. char help [MAX_LINE];
  73. char longest [MAX_LINE]; //longest line
  74.  
  75. while ((ch=getchar())!='n'){ //first line
  76. longest[i]=ch;
  77. ++i;
  78. }
  79.  
  80. max=i;
  81. i=0;
  82. length=0;
  83. while ((ch=getchar())!=EOF){
  84. line[i]=ch;
  85. help[j]=ch;
  86. ++j;
  87. ++i;
  88. ++length;
  89. if (ch=='n'){
  90. help[j]='';
  91. if (length-1>max){
  92. max=length-1;
  93. j=0;
  94. printf("Longest -> %s",help);
  95. }
  96. else {
  97. memset(help,0,100); //erase elements
  98. }
  99. length=0;
  100. }
  101.  
  102. }
  103. return 0;
  104. }
  105.  
  106. help[0] = '';
  107.  
  108. help[j]=ch;
  109. ++j;
  110.  
  111. help[j++] = ch;
  112.  
  113. while ((ch=getchar())!=EOF){
  114.  
  115. while ((ch = getchar()) != EOF) {
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement