-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy path1-17.c
44 lines (34 loc) · 831 Bytes
/
1-17.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
/*
* Exercise 1-17. Write a program to print all input lines that are longer than
* 80 characters.
*
* By Faisal Saadatmand
*/
#include <stdio.h>
#define MAXLEN 1000 /* maximum input line length */
#define NCHARS 80 /* number of characters per line,
including the newline character */
/* functions */
int getLine(char [], int);
/* getLine function: read a line into s, return 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;
++i;
}
s[i] = '\0';
return i;
}
int main(void)
{
int len; /* current line length */
char line[MAXLEN]; /* current input line */
while ((len = getLine(line, MAXLEN)) > 0)
if (len > NCHARS)
printf("%s", line);
return 0;
}