summaryrefslogtreecommitdiff
path: root/usr.bin/learn/lib/C/L5.1c
blob: 44c3f59060c06b21d85e269deea968ce06e51e03 (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
#print
(Section 1.5)
Write a program which reads one character from
its input; if that character is ? it prints "yes",
otherwise it prints "no".
Compile it, test it, and then type ready.
#once #create Ref1
? is here
#once #create Ref2
no ? at beginning
#user
a.out <Ref1 >test1
a.out <Ref2 >test2
grep yes test1 >/dev/null && grep no test2 >/dev/null
#succeed
This is one possible solution

main()
{
	if (getchar() == '?')
		printf("yes\n");
	else
		printf("no\n");
}

The indenting and general formatting of C programs
should be done so you make the structure clear,
like the code above.
#log
#next
5.1d 10