我这里有一些奇怪的输出。你能解释一下为什么以及如何解决它吗?
int inp_str(char * string, char ** pointers[])
{
char * tmp[stringsCount];
if (strlen(string) > maxlen)
return (-1);
else {
tmp[count] = malloc(sizeof(char) * strlen(string));
strcpy(tmp[count], string);
pointers[count] = &tmp[count];
count++;
}
return count;
}
int main(){
//char * strings[stringsCount];
char ** pointers[stringsCount];
inp_str( "sdasya", pointers);
inp_str( "dasd", pointers);
inp_str( "qwe", pointers);
inp_str( "dasd", pointers);
//sort(pointers, count);
printf("%s", *pointers[0]);
printf("\n%s", *pointers[1]);
printf("\n%s", *pointers[2]);
printf("\n%s", *pointers[3]);
}
这是输出:
sdasya
��uNH��H�l$ H�\$L�d$(L�l$0H��8�f.�
qwe
�bs7
PS。stringsCount 是常数;计数 = 0