31 lines
		
	
	
		
			766 B
		
	
	
	
		
			C
		
	
	
	
	
	
		
		
			
		
	
	
			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; | ||
|  | } |