Here of your code introduces the problem:
reference[no_of_ref]=malloc(strlen(temp_in) + 1);
reference[no_of_ref++]=temp_in;
That's because assignment of pointers in C affects pointers and only pointers, which won't do anything with its contents. You shall use things like memcpy
or strcpy
:
reference[no_of_ref]=malloc(strlen(temp_in) + 1);
strcpy(reference[no_of_ref], temp_in);
no_of_ref+=1;