when I read from stdin like this:
size_t bufSize = 1024;
unsigned char inputBuffer[bufSize];
size_t readNum = 0;
readNum = fread(inputBuffer, sizeof(unsigned char) * bufSize, 1, stdin);
in the readNum are stored number of object, this mean when I read from stdin 1024 bytes, the readNum has value 1. But when I read from stdin < 1024 bytes, than readNum has value 0. Question is, how can I recognize how many bytes was read from stdin when the number is less then 1024?
Use
readNum = fread(inputBuffer, sizeof(unsigned char), bufSize, stdin);You’re trying to read
bufSizeelements, each with a sizesizeof(char)– not one element with a size ofbufSize * sizeof(char)– so yourfreadcall should reflect that.