Quote:
Originally Posted by microbet
I don't fget any of that, so feel free to explain which way is better and why.
fread will read from a file into a buffer like this:
fread(buffer, n, nmemb, file pointer)
n is the number of bytes you are requesting nmemb times, so if you do fread(buffer, 1, 8192, fp) you are requesting 1 byte read 8192 times, vs 8192 bytes 1 time. Then it will return whatever the successful number of nmemb reads was.
but fread will (presumably) read byte by byte anyway into its own internal buffer using getc, so the assumption can be made it doesn’t matter which one you use. But implementations of fread can vary because the standard doesn’t really necessitate n * nmemb calls to getc. It may implement it completely differently if it wishes, as long as it follows the standard.
The number of getc calls is important because it makes a system call which is very expensive.