update
This commit is contained in:
30
DEV.1.1/CM2TEST/CM2A/4.Sensation-Fichiers.c
Normal file
30
DEV.1.1/CM2TEST/CM2A/4.Sensation-Fichiers.c
Normal 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;
|
||||
}
|
Reference in New Issue
Block a user