BSD 4_3 development
[unix-history] / usr / src / usr.lib / learn / C / L5.1c
#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