File:  [CSRG BSD Unix] / 43BSD / usr.lib / learn / C / L5.1c
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
(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

unix.superglobalmegacorp.com

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