A small Windows program in C++ that shows any file as a wave: open a file and choose Start Drawing, and it reads 100 bytes spread through the file and draws them as a line, each byte's value its height. I wrote it while learning MFC and Visual C++ 5.0 in haste, before emigrating to the USA for my first job there. The window below runs it as it was; the menus, the toolbar and the dialogs are the ones it had, and you can resize the window. The Open dialog has a few files to try, or you can pick one of your own; nothing leaves your computer.
i += step, but each
time it reads a byte, which moves the file on by one, and then seeks another step. So the reads drift ahead of
i, and the last ones fall past the end of the file, where nothing is read and the byte before is used again.
In a file under 200 bytes, step is 1 and it reads every other byte, so the right half of the wave is flat.data[], over end, and on into the heap. For a large
file it is only one byte too many, which landed in padding; NOTE.TXT shows a small file.end is set to one less than the count, and the drawing stops before
data[end].end = 0 and a division by it. An empty file set
end to −1, which is 4,294,967,295 as a DWORD, and the drawing set out to read that many bytes. Try
ONE.TXT and EMPTY.TXT.data[0] to data[100], one past the end; the wave is upside
down, larger values lower; it starts at x = 5 and then goes back to x = step; and it covers the window only as far as
a whole number of pixels per point reaches.Fixed reads 100 bytes spread evenly through the file, draws them all across the whole window with larger values higher, and says so when a file is empty. My 32×32 icon, the wave, is in the About box; the title bar shows the 16×16 icon, which was still AppWizard's MFC one, as it was. The port was checked against the original C++, compiled with small stand-ins for MFC: in 206 sessions of opening, drawing and resizing, with files from 0 to a million bytes, it draws the same lines and crashes in the same places.