Blob


1 /* 1-17. Write a program to print all input lines that are longer than 80
2 * characters
3 */
5 /* MAXLINE has been reduced for easier testing */
6 #include <stdio.h>
7 #define MAXLINE 1000
9 int getlin(char line[], int maxline);
10 void copy(char to[], char from[]);
12 main()
13 {
14 int len; /* current line length */
15 char line[MAXLINE]; /* current input line */
17 while ((len = getlin(line, MAXLINE)) > 0) {
18 if (len > 80)
19 printf("%s", line);
20 }
21 return 0;
22 }
24 int getlin(char s[], int lim)
25 {
26 int c, i;
28 for (i=0; i<lim-1 && (c=getchar())!=EOF && c!='\n'; ++i)
29 s[i] = c;
30 if (c == '\n') {
31 s[i] = c;
32 ++i;
33 }
34 s[i] = '\0';
35 return i;
36 }
38 void copy(char to[], char from[])
39 {
40 int i;
41 i = 0;
42 while ((to[i] = from[i]) != '\0')
43 ++i;
44 }