Thank you for the replies thus far.
frob23 -- "nailing jelly to a tree" -- that's pretty funny, it sounds like you're very motivated. Thanks for the inspiration
I'm learning C mainly because I like it and think it will make for a strong foundation (when I get into a specific area -- like computer graphics, or whatever). And I'm learning a lot more than just C by going through the process of solving the exercises. For example, I've read about several programming methodologies (like extreme programming, or test-driven development), and the recurring theme seems to be to write tests, so that's what I'm doing, too.
For example, to test two of the exercises (exercise 20 and 21: detab and entab respectively), I eventually (after some thought and after failing with testing them manually) wrote the following python script which randomly generates a test:
# i've had some success before with using
# randomly generated tests -- it had
# discovered some bugs in a program
# when i thought it was well tested,
# until i tried the random approach,
# that is.
# this function basically prints
# a bunch of characters, with blanks
# and newlines among them
# (NO tabs however)
f = open( "205.test", "w" )
for i in range(nchars):
u = random.uniform(0,1)
if u < 0.05:
elif u < 0.85:
u = random.randrange(33,127)
# generate a test file to test 20.detab and 21.entab
# the resultant test file is fed into 21.entab first,
# then the result into 20.detab and then
# the result of that is compared with the original
# test file -- they should match
And then I added the following to my Makefile:
./21.entab < 205.test > 21.result
./20.detab < 21.result > 20.result
diff 205.test 20.result
so as to automate the process of testing. I can then just type 'make test205' to test two programs at once with a randomly generated test.
What do you guys think? Good idea? I just though I'd post it, because I felt as though I learnt a valuable lesson. Maybe some other programming newbie will find this useful, too.