Haven't read all your code, but this bugs me:
while(*array != '\0') {
array is a **char
. This means *array is a *char
. But you compare it to a char ('\0'
). You probably meant NULL
?
And now to your bug:
*array=str;
This is the bad line. You aren't copying the string! You are just pointing to the same place in memory!
This means that if you change the string pointed to by str
, the string pointed to by *array
will change too!
So once you add a string using ut_name
and then changing ut_name
and adding it again - it finds it already, because you have the same memory for ut_name
and *array
.
Anyway - use strcpy
(after allocating memory!!!) instead of that line *array=str
and everything will work fine.