exc/k&r/01-a-tutorial-introduction/01-17.c

31 lines
591 B
C

#include <stdio.h>
/* print line number and lines longer than 80 chars (excluding \n) */
int main()
{
int c, i, ln;
char buff[81]; /* +1 for \0 */
ln = 1;
buff[80] = '\0';
for (i = 0; (c = getchar()) != EOF; ++i) {
if (c == '\n') {
if (i > 80)
putchar('\n');
++ln;
i = -1;
} else if (i < 80) {
buff[i] = c;
} else {
if (i == 80)
printf("%d %s", ln, buff);
putchar(c);
}
}
if (i > 80 && c != '\n')
putchar('\n');
}