problem with fread into array
I am trying to read a binary file:
Code:
FILE *fl = fopen("dta.bin", "rb");
if ( (fopen("data.bin", "rb" )) == NULL)
{
printf("input file not found");
getchar();
exit(1);
}
fseek(fl, 0, SEEK_END);
long len = ftell(fl);//get length of file
char *ret = (char*) malloc(len);
if(ret == NULL)
{
printf("\nInsufficient memory to read file\n");
getchar();
}
fseek(fl, 0, SEEK_SET);
//Read data from file into array
fread(ret, 1, len, fl);
fclose(fl);
printf ("size of array: %i", sizeof(ret));
printf ("\nlength of file: %i", len);
getchar();
I can't see what is wrong with the code but the char array "ret" is not getting the values from my input file.
The output says:
"size of array:4
length of file: 102727488"
when they should be the same length.