|
From: Martin W. <ic...@ma...> - 2018-01-09 08:44:50
|
fgetc() is the standard 'C' method for reading a byte at a time from a binary file, so it's reasonable to use $fgetc for the same purpose. You indicate that it's a binary file when you open the file. The attached test program demonstrates that the 'C' fgets() function doesn't skip null characters. Martin Cary R. wrote: > NULL bytes in a string is always dangerous. The strlen() is just being used to determine the number of bytes (what $fgets() returns). It returns the bytes read as a string to the first argument which the runtime is likely correctly using the NULL byte to indicate the end of the string. > > I agree with Niels that $fread() is a better choice. If you need more control than look at $fscanf(). > Cary > > On Monday, January 8, 2018, 11:13:45 PM PST, Niels Möller <ni...@ly...> wrote: > > Martin Whitaker <ic...@ma...> writes: > >> To work round this, try using $fgetc. > > Wouldn't $fread be a more natural choice for reading binary files? > > Regards, > /Niels > |