blob: 4e3f71ab878f814f4c5940e150b81765d5b8417e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
#include <stdio.h>
#define MAXLINE 1000
int gline(char str[], int len);
void cp_str(char to[], char from[]);
int
main(void)
{
int len, max;
char str[MAXLINE];
char mstr[MAXLINE];
max = 0;
while ((len = gline(str, MAXLINE)) > 0)
if (len > max) {
cp_str(mstr, str);
max = len;
}
if (max > 0)
printf("\nlength: %d\n%s", max, mstr);
return 0;
}
int
gline(char str[], int len)
{
int i;
char input;
i = 0;
while (i < len-1) {
input = getchar();
if (input == EOF)
break;
else if (input == '\n')
break;
str[i] = input;
i++;
}
if (input == '\n' && i < len-1) {
str[i] = '\n';
++i;
}
str[i] = '\0';
return i;
}
void
cp_str(char to[], char from[])
{
for(int i =0; (to[i] = from[i]) != '\0'; i++)
;
}
|