as you can read the contents of a file ".bin" in which we have inserted whole numbers.
I would like to know how you can read that file, I used the "fread" tool but it does not show me anything or random numbers.
The ".bin" file contains the following with the hexdump command:
0000000 0020 0000 000b 0000 0061 0000 0012 0000
0000010 0017 0000 000a 0000
0000018
That is, they are integers numbers that I have previously entered using an array.
The goal is to be able to read those numbers, that is, that file.
This is the code of my program:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main()
{
unsigned short lenght;
int i;
char * token;
int array[6];
float size;
FILE *file;
file= fopen("numeros.bin", "rb");
if (file==NULL)
{
printf("Error file not found\n");
return 1;
}
printf("-----------------------------\n");
printf("Quin nombre vols mostrar del fitxer binari:\n");
scanf("%u", &lenght );
fseek(file, lenght, SEEK_SET);
token=(char *)malloc(lenght+1);
fread( token, sizeof(lenght), 1, file);
printf("%x\n", token);
printf("-----------------------------\n");
fclose(file);
return 0;
}