I am trying to adapt a matlab program to C, my problem is in the fwrite
and fread
function. On matlab I have:
fid = fopen ('sweep_100_3400.pcm','rb');
s = fread (fid, 'int16');
My doubt is, in C there are two more parameters in fread
and fwrite
function.
fread(void*, size_t, size_t, FILE*);
fwrite(const void*, size_t, size_t, FILE*);
In my C code I have:
arq = fopen("C:\\Users\\iago_\\Desktop\\MediaMovel\\sweep_100_3400.pcm", "rb");
fread(x, sizeof(double), itera, arq);
fclose(arq);
x
is the vector where the data of my file will be saved.
sizeof(double)
is the length of the data (I've declared all double
)
arq
is the pointer to the file.
The third parameter is a size_t
, to adapt my matlab program, in this parameter should I use the media length or the vector size?
(I am encoding a moving average, the media length is informed by the user and the vector size is the length of my input file).
For the fwrite
function I have the same doubt about the parameters.
arq=fopen("C:\\Users\\iago_\\Desktop\\MediaMovel\\saida_medial_movel_c.pcm", "wb");
fwrite(saida, sizeof(double), itera, arq);
fclose(arq);