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

#print
Write a program to copy its input to its output,
replacing each string of one or more blanks by
a single blank.
#once #create Ref
   This    has   lines   with several     blanks    
including some in  funny places.    
#once #create Ref1
          
#once #create Answer
 This has lines with several blanks 
including some in funny places. 
 
#user
a.out <Ref >test
a.out <Ref1 >>test
#cmp test Answer
#succeed
One way:

 #include <stdio.h>

main()
{
	int c;

	for (c = getchar(); c != EOF; ) {
		putchar(c);
		if (c == ' ')
			while ((c = getchar()) == ' ')
				;
		else
			c = getchar();
	}
}
#log
#next
9.1a 10

unix.superglobalmegacorp.com

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