I am having problem while creating dynamic array using both malloc and calloc.
int main() { float *xd_real_send; int Nooflines_Real; int *X; float test[500]; Nooflines_Real = count_lines(infile); printf("Nooflines_Real: %d\n", Nooflines_Real); X = (int *) malloc(Nooflines_Real*sizeof(int)); xd_real_send = (float *) calloc (Nooflines_Real,sizeof(float)); printf("size of X %d, test %d and size of xd_real_send %d\n", sizeof(X)/sizeof(int),sizeof(test)/sizeof(float), sizeof(xd_real_send)/sizeof(float));fflush(stdout); }
And the output is
Nooflines_Real: 40 size of X 2, test 500 and size of xd_real_send 2
Could you please tell what Am I doing wrong.
malloc
orcalloc
. – Kerrek SBsizeof(X)
is thesizeof(int*)
. – hmjd