Stream reader/writer for PNM images in C