I've written a program that reads an whole file via fgetc
:
while ((c = fgetc(f)) != EOF) { ... }
But the program is too slow. When I changed fgetc
to fread
,
static unsigned char buf[4096];
while ((n = fread(buf, 1, sizeof(buf), f)) > 0) { ... }
the program works about 10 times faster.
Why? As I know, fgetc
is a buffered function, so it should work as fast as the second version with explicit buffer, isn't it?