I'm trying to write some bytes array into a file using fwrite() in c. The code is as following
typedef unsigned char byte;
byte buffer[100];
generate_n(buffer, 48, rand);
int numByte = 48;
file = fopen("test", "wb+");
fwrite(buffer, sizeof(byte), numByte, file);
I checked numByte value and the file written. But sometimes the file size is numByte + 1 bytes. Not always, but sometimes. It's very strange. Could anyone help me? Thanks in advance.
ps. Some people said that they can't understand this happens sometimes, not always, but it is really true. Sometimes fwrite() writes 48 bytes, sometimes it writes 49bytes. I can't understand, too.