Advertisement
Guest User

Untitled

a guest
Dec 4th, 2016
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.52 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <locale.h>
  3.  
  4. #define MAXLINE 1000 /* максимальный размер вводимой строки */
  5.  
  6. int getline(char linef[]);
  7. void copy(char to[], char fromf[]);
  8. /* печать самой длинной строки */
  9. int main()
  10. {
  11.     setlocale(LC_ALL, "Rus");
  12.     int len; /* длина текущей строки */
  13.     int max; /* длина максимальной из просмотренных строк */
  14.     char line[MAXLINE]; /* текущая строка */
  15.     char longest[MAXLINE]; /* самая длинная строка */
  16.     max = 0;
  17.     while ((len = getline(line, MAXLINE)) > 0)
  18.         if (len > max)
  19.         {
  20.             max = len;
  21.             copy(longest, line);
  22.         }
  23.         if (max > 0) /* была ли хоть одна строка? */
  24.         printf("%s", longest);
  25.         return 0;
  26. }
  27. /* getline: читает строку в s, возвращает длину */
  28. int getline(char s[], int lim)
  29. {
  30.     int c, i;
  31.     for (i = 0; i < lim-1 && (c = getchar()) != EOF && с != '\n'; ++i)
  32.     s[i] = c;
  33.     if (c == 'n';
  34.     {
  35.         s[i] = c;
  36.         ++i;
  37.     }
  38.     s[i] = '\0';
  39.     return i;
  40. }
  41. /* copy: копирует из 'from' в 'to'; to достаточно большой */
  42. void copy(char to[], char from[])
  43. {
  44.     int i;
  45.     i = 0;
  46.     while ((to[i] = from[i]) != '\0')
  47.     ++i;
  48. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement