Code: Select all
#include <stdio.h>
...
size_t bytes_read;
char buf[100];
FILE *fp;
...
bytes_read = fread(buf, sizeof(buf), 1, fp);
...
Am I crazy?
Code: Select all
#include <stdio.h>
...
size_t bytes_read;
char buf[100];
FILE *fp;
...
bytes_read = fread(buf, sizeof(buf), 1, fp);
...
Does it matter if you ask for one item (that is "sizeof(buf)" bytes big) or ask for "sizeof(buf)" items that are 1 byte big? The only real difference is the return value.dmatlack wrote:fread(ptr, size, nitems, stream) only returns the number of bytes read if size is 1, but in the example code size is sizeof(buf) and nitems is 1. Thus this call to fread() will either return 1 on success, 0 if EOF reached, or < 0 if error.
Am I crazy?
Ah it's fixed there. Thanks!Brynet-Inc wrote:The latest is Issue 7, 2013 or POSIX.1-2008 TC1-2013.