Quote:
data = (int*)realloc(arr,sizeof(int));
Check the above line: there is no 'new part' in the array because you forgot to multiply
sizeof(int)
, change to, say
data = (int*)realloc(arr,12*sizeof(int));
Please note: you must NOT free
data
after reallocating.