blob: 5fca79c6406f761fd3b3dba4794f52d834e20d8d (
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
|
#include <stdio.h>
#define MAXLINE 1000
int gline(char str[], int len);
int
main(void)
{
int len;
char str[MAXLINE];
while ((len = gline(str, MAXLINE)) > 0)
if (len > 80)
printf("\nlength: %d\n%s\n", len, str);
return 0;
}
int
gline(char str[], int len)
{
int i;
char input;
for (i = 0; i < len-1 && (input = getchar()) != EOF && input != '\n'; i++)
str[i] = input;
if (input == '\n' && i < len-1) {
str[i] = '\n';
++i;
}
str[i] = '\0';
return i;
}
|