文字の配列の配列を再割り当てする際に問題に直面しています。GDBでデバッグしようとすると、realloc(): invalid old size: 0x00000000006042f0 error
. コードは次のとおりです。
int wordCount = 1;
int charCount = 1;
char** words = (char**)malloc(wordCount*sizeof(char*));
char* words[0] = (char*)malloc(charCount*sizeof(char));
char c = getNextChar(file);//it will read the content of the file character by character
while(c!='\0')//read
{
words[wordCount-1] = (char*)realloc(words[wordCount-1],(charCount+1)*sizeof(char));
charCount++;
c = getNextChar(file);
if(c=='\n' || c==' ')
{
words = (char**)realloc(words, (countWord+1)*sizeof(char*)); //this is where I got the error
wordCount++;
c = getNextChar(file);
}
}
なにか提案を?ありがとう