[To any mod considering deleting this question - please don't. Either my or Steve Jessop's code may well be helpful to reference from questions regarding reading text files using C.]
This question has generated the usual amount of sound and fury re the relative merits of C and C++. But something that never seems to get introduced into these discussions is actual code. I thought I would change that, so I set myself a small test:
Create a command line utility that reads zero or more files into memory and then outputs them in a random order. Each line must be output only once. The program to be written in C++98 or C89, using only their standard library functions.
The result is the two programs I present as answers below. I'd be grateful if you would vote on the one you would rather be tasked with maintaining.
Some notes:
The code is written in my own idiomatic style. The only difference being that there are no comments and less vertical whitespace than I would normally use.
The random number generator is naive, but is the same in both cases. so it dodn't seem worth improving at this point.
The C program reads only lines up to a fixed length - I couldn't be bothered implementting a true variable length file reading function. It would probably have added about 10 more lines to the code.
There is no check for memory exhaustion in either version.
Ah well, I thought it would get closed fairly quickly. Still, I enjoyed writing the code and seeng other people's code too - it seems to me that SO is lacking in that regard. Thanks to all who took part.