Currently have a program where I read a binary file where the first 4 bytes contains an integer n which is the amount of double values in the file, and the rest of the file has 8n bytes containing an array of double values.
I can read the file fine and determine the coefficients, the issue lies with detecting if the information given by n is correct. My question is why does
sizeof(*coeff_values_p)
return a value of 4 instead of 8n. I am using a file where n=29
so shouldn't the size be 232?
Any help would be appreciated.
#include "Ass-01.h"
#include <stdio.h>
int read_coefficients(int *coeff_num_p, double **coeff_values_p, char
*filename)
{
//uint32_t n; //Number of coefficients
FILE *f; //File to be opened
//File reading storing the value of n
f = fopen(filename, "rb");
fread(coeff_num_p, sizeof(uint32_t), 1, f);
*coeff_values_p = malloc(8 * *coeff_num_p);
fread(*coeff_values_p, sizeof(uint64_t), *coeff_num_p, f);
if (sizeof(*coeff_values_p) != (*coeff_num_p*sizeof(uint64_t)))
{
return -1;
}
else
{
return 0;
}
}