File:  [CSRG BSD Unix] / 42BSD / usr.lib / learn / C / L5.1d
Revision 1.1.1.1 (vendor branch): download - view: text, annotated - select for diffs
Tue Apr 24 16:12:54 2018 UTC (8 years, 1 month ago) by root
Branches: MAIN, BSD
CVS tags: HEAD, BSD42
BSD 4.2

#print
Write a program that counts the blanks, tabs, and newlines
in its input, and prints the total.  Don't forget to
define the value of EOF at the beginning of your program.
The best way is to add

 #include <stdio.h>

as the first line of your program.
The ____must be in column 1.
(See page 143 of the C book.)
You may also have to say

cc name.c -lS

to compile the program.
#once #create Ref
This is some junk that
contains
	blanks
	tabs
	and newlines.
#user
a.out <Ref >test1
a.out </dev/null >test2
grep 13 test1 >/dev/null || grep 0 test2 >/dev/null
#succeed
One possible solution:

 #include <stdio.h>

main()
{
	int n, c;

	n = 0;
	while ((c = getchar()) != EOF)
		if (c == ' ' || c == '\t' || c == '\n')
			n++;
	printf("%d\n", n);
}

This program won't work on huge files, because an int
isn't big enough.
#log
#next
5.1e 10
5.2e 5

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.