From 6c133eab750473e3b0e1a342fafe55ba6f1a9c93 Mon Sep 17 00:00:00 2001 From: Zhineng Li Date: Wed, 4 Feb 2026 10:49:18 +0800 Subject: ch01-17: print lines that are longer than 80 characters --- ch01/ex17-print.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 ch01/ex17-print.c 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 +#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