This commit is contained in:
NaiJi ✨ 2024-05-01 11:40:22 +04:00
parent fbc5c728ea
commit b5f95e1eb4
1 changed files with 51 additions and 0 deletions

View File

@ -0,0 +1,51 @@
#include <stdio.h>
#define MAXLINE 10
int _getline(char line[], int maxline);
void copy(char to[], char from[]);
main()
{
int len;
int max;
char line[MAXLINE];
char longest[MAXLINE];
max = 0;
while ((len = _getline(line, MAXLINE)) > 0)
if (len > max)
{
max = len;
copy(longest, line);
}
if (max > 0)
printf("%d: %s\n", max, longest);
return 0;
}
int _getline(char s[], int lim)
{
int c, i, j;
for (i = 0; (c = getchar()) != '\n'; ++i)
{
if (i < lim - 1)
s[i] = c;
}
j = i;
if (j > lim - 1)
j = lim - 1;
s[j] = '\0';
return i;
}
void copy(char to[], char from[])
{
int i;
i = 0;
while ((to[i] = from[i]) != '\0')
++i;
}