File:  [CSRG BSD Unix] / 42BSD / usr.lib / learn / C / L15.1a
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 reads in lines one at a time,
and prints them out if their length (including
the newline) is odd.
You can use the function getline if you like; the object
file is in getline.o.
Compile and run it, then type "ready".
#once #create Ref1
this line contains an odd number of letters!
this line, however, contains an even number of letters!
#once #create Ref2
this line contains an odd number of letters!
#once cp %s/getline.o .
#user
a.out <Ref1 >x1
#cmp x1 Ref2
#succeed
/* It's certainly easiest with getline: */

 #include <stdio.h>

main()
{
	char line[500];
	int n;

	while ((n = getline(line, 500)) > 0)
		if (n % 2 == 1)
			printf("%s", line);
}
#log
#next
15.1b 10

unix.superglobalmegacorp.com

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