我对 realloc 有问题。这是我的函数,它从输出中读取单词并在检测到 EOF 时终止。该函数导致内存泄漏,以下程序抛出 SIGSEGV 或 SIGABORT。有什么问题?
int inx=0;
char **wordList=NULL;
int v;
char tmpArr[100];
do
{
v=scanf("%s",tmpArr);
if(v!=-1)
{
char* word=(char*)malloc(strlen(tmpArr)+1);
strcpy(word,tmpArr);
char**more=(char**)realloc(wordList,sizeof(char*)*(inx+1));
if(more!=NULL) {wordList=more;} else return 1;
wordList[inx++]=word;
printf("%d\n",inx);
}
}