summaryrefslogtreecommitdiff
path: root/usr.bin/learn/lib/C/L15.1b
blob: d0032a8397a591f3ff43e5fb95b4c3eed5f2e510 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#print
Write a program that reads in lines, and prints each out
in reverse order (except that the newline should be
at the end).
Thus the line
cat food
should come out as
doof tac
Compile it and run it, then type "ready".
#once #create Ref1
This is odd.
This is even.

#once #create Ref2
.ddo si sihT
.neve si sihT

#once cp %s/getline.o .
#user
a.out <Ref1 >x1
#cmp x1 Ref2
#succeed
/*	one way to do this */
 #include <stdio.h>

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

	while ((n = getline(line, 500)) > 0) {
		for (n -= 2; n >= 0; n--)
			putchar(line[n]);
		putchar('\n');
	}
}
#log
#next
17.1a 10
16.2a 5