0
我想從標準輸入標記字符串。我只對字符感興趣,並建立每個字符串的數組(忽略非字符)。對於當我從標準輸入讀取24個或更多字符某種原因,我收到錯誤:免費():無效的下一個大小(快)錯誤
免費():無效的下一個尺寸(快速):
這是相關的代碼......它工作正常上小串(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;
}
錯誤的詳細信息通常是有用的。 – zero323