Are you sure you need those for getting a value whose upper range requirements can be met by `char`?
Processing a binary file would look something like this. Not sure if this will compile as I don't have a compiler handy, and there are bound to be bugs, but it should give you a rough idea on how it works.
Code:
size_t block_size = x / CHAR_BITS; // read this many bytes
FILE *fp = fopen(input_file, "rb");
if (!fp) {
fprintf(stderr, "FATAL: Could not open file %s\n", input_file);
exit(EXIT_FAILURE);
}
unsigned char *block = malloc(block_size);
if (!block) {
fprintf(stderr, "FATAL: Memory allocation failed\n");
exit(EXIT_FAILURE);
}
size_t bytes_read;
while (1) {
bytes_read = fread(block, 1, block_size, fp);
// process the block here, it's binary data
if (bytes_read != block_size) {
if (feof(fp))
break; // files has been fully read
if (ferror(fp)) {
fprintf(stderr, "FATAL: Error reading file %s\n", input_file);
// release resources
exit(EXIT_FAILURE);
}
}
}
// rewind the file with `fseek()` if you intend to do any other processing on it