At first I could not get fread() to read anything from card.raw, but then I made a change to the second and third arguments, and the function worked. Although intuition led me to the change, the two versions look equivalent to me.
Can someone explain why the first version did not read any elements (meaning the fread() returned 0), whereas the second did?
For the sake of other learners, I'm only including the code that I think is relevant to the question.
Outside of main:
#include <stdio.h> #include <stdlib.h> #include <stdint.h> typedef uint8_t BYTE;
First version of fread() (did not work):
while (fread(buffer, sizeof(BYTE), 512, card_file) == 1)
This version failed the first test, returning 0 and thus false, never entering the while loop.
Second version of fread() (worked, e.g. read all 512B blocks of data):
while (fread(buffer, sizeof(buffer), 1, card_file) == 1)
While I'm glad I got the program to work, it bugs me that I don't understand the difference between the two versions of fread().