aboutsummaryrefslogtreecommitdiff
path: root/1/8.c
blob: 30ed644a110929aa10173336db11610748216cb2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
/*
	Exercise 1-8. Write a program to count blanks, tabs, and newlines.
	===
*/

#include <stdio.h>

int main () {
	int c, nl, bl, tb;

	nl=0;bl=0;tb=0;	/* newlines, blanks, tabs count */
	while ((c=getchar())!=EOF) {
		if (c=='\n')	nl++;
		if (c==' ')		bl++;
		if (c=='\t')	tb++;
	}

	printf("\nnewlines: %d\nblanks: %d\ntabs: %d\ntotal: %d\n", nl, bl, tb, nl+bl+tb);
}