I'd guess that rob_au
is correct about importing the constants. Read flock
to see how to import the constants.
As for the garbage in the file.. there's one thing that I see that could be causing it. When you read in the data, where's the file pointer? You then truncate the file. I'm not positive, but I think your pointer is beyond the end of the file.
Before you truncate it, do a
seek FH, 0, 0;
I did a quick test and without the seek
, I couldn't see anything in the file. When I used seek
, everything printed fine.
Hope this helps..