stdin から文字列をトークン化しようとしています。私は文字だけに興味があり、各文字列の配列を作成します (文字以外は無視します)。何らかの理由で、stdin から 24 文字以上を読み取ると、次のエラーが表示されます。
free(): 次のサイズが無効です (高速):
これは関連するコードです...小さな文字列(23文字以下)でうまく機能します
char **tokenize(int *nbr_words) {
char **list = calloc(INITIAL_SIZE, sizeof(char *));
char * temp = NULL;
temp = malloc(sizeof(200));
while(fgets(temp,200,stdin)){
char * newWord = NULL;
newWord = malloc(sizeof(100));
int i = 0;
while(temp[i] != '\n'){
if(isalpha(temp[i]) && temp[i+1] != '\n'){
strncat(newWord,&temp[i],1);
i++;
}
else if(isalpha(temp[i]) && temp [i+1] == '\n'){
strncat(newWord,&temp[i],1);
list[*nbr_words] = newWord;
*nbr_words += 1;
printf("%s\n",list[*nbr_words -1]);
i++;
if(*nbr_words % 10 == 9){
list = realloc(list, *nbr_words + 10);
}
free(newWord);
newWord = malloc(sizeof(100));
*newWord = NULL;
}else{
if(*newWord == NULL){
i++;
}
else if(*nbr_words % 10 != 9){
list[*nbr_words] = newWord;
*nbr_words += 1;
printf("%s\n",list[*nbr_words-1]);
i++;
free(newWord);
newWord = malloc(sizeof(100));
*newWord = NULL;
}else{
list = realloc(list, *nbr_words + 10);
list[*nbr_words] = newWord;
*nbr_words += 1;
printf("%s\n",list[*nbr_words-1]);
i++;
free(newWord);
newWord = malloc(sizeof(100));
*newWord = NULL;
}
}
}
free(temp);
temp = malloc(sizeof(200));
*temp = NULL;
}
return list;
}