Files
DEV/DEV.1.1/CM2TEST/CM2A/4.Sensation-Fichiers.c
Emmanuel Srivastava 6bcd12a191 update
2024-12-11 11:57:32 +01:00

31 lines
766 B
C

#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;
}