This commit is contained in:
Emmanuel Srivastava
2024-12-11 11:57:32 +01:00
parent 7bc0c88705
commit 6bcd12a191
24 changed files with 132 additions and 34 deletions

View File

@@ -0,0 +1,30 @@
#include <stdio.h>
#include <stdlib.h>
int main(void) {
FILE *flux = fopen("reitne", "rb"); /* Open the file in binary mode */
unsigned char bytes[4];
unsigned int num;
if (flux == NULL) {
perror("Error opening file");
return EXIT_FAILURE;
}
if (fread(bytes, 1, 4, flux) != 4) {
perror("Error reading file");
fclose(flux);
return EXIT_FAILURE;
}
/* Combine the bytes into an integer (big-endian to little-endian)*/
num = (unsigned int)bytes[0] * 256 * 256 * 256 +
(unsigned int)bytes[1] * 256 * 256 +
(unsigned int)bytes[2] * 256 +
(unsigned int)bytes[3];
printf("%u\n", num);
fclose(flux);
return 0;
}