-
Notifications
You must be signed in to change notification settings - Fork 0
/
filter80.c
54 lines (37 loc) · 999 Bytes
/
filter80.c
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
/* Write a program to print all input lines that are longer than 80 characters */
#include <stdio.h>
#define MAXLEN 1000 // max length of one line
int copy(char src[], char dst[]);
int getline_(char s[], int lim);
int main() {
int len;
int i = 0;
char s[MAXLEN];
char slong[MAXLEN][MAXLEN];
printf("Inputs:\n");
while ((len = getline_(s, MAXLEN)) > 0)
if (len > 80)
copy(s, slong[i++]);
if (i > 0) {
printf("\n\nLines longer than 80 characters:\n");
while (i >= 0)
printf("%s\n", slong[--i]);
}
}
/* Line captor & Return line's length */
int getline_(char s[], int lim) {
int c, i;
for(i = 0; (i<lim-1) && ((c=getchar())!=EOF) && (c!='\n'); ++i)
s[i] = c;
if (c == '\n')
s[i++] = c;
s[i] = '\0';
return i;
}
/* Copy line from `src` to `dst` */
int copy(char src[], char dst[]) {
int i;
for (i = 0; (dst[i] = src[i]) != '\0'; ++i)
;
return 0;
}