You allocation is wrong for string in side loop:
*(subNames+i)= (char*)malloc(sizeof(char*));
should be:
*(subNames+i)= malloc(sizeof(char) * (string_lenght + 1));
Additionally, don't use fflush(stdin);
it causes undefined behavior on other then Microsoft compilers, Also don't cast returned address of malloc()
and calloc()
in C
Read: Why fflush(stdin)
is wrong?, and read: fflush
@msdn.microsoft.