diff options
Diffstat (limited to 'ch01/ex17-print.c')
| -rw-r--r-- | ch01/ex17-print.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/ch01/ex17-print.c b/ch01/ex17-print.c new file mode 100644 index 0000000..35bb18a --- /dev/null +++ b/ch01/ex17-print.c @@ -0,0 +1,31 @@ +#include <stdio.h> +#define MAXLINE 1000 /* maximum input line size */ + +int getln(char line[], int maxline); + +/* print lines that are longer than 80 characters */ +int main() +{ + int len; /* current line length */ + char line[MAXLINE]; /* current input line */ + + while ((len = getln(line, MAXLINE)) > 0) + if (len > 80) + printf("%s", line); + return 0; +} + +/* getln: read a line into s, return length */ +int getln(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; +} |
