우리가 사용하고있는 코드에 오류가있어 누군가 디버깅하는 데 도움이되는지 궁금합니다. malloc 오류가 발생하는 것 같습니다. 감사.구조체 배열로 단어를 읽는 기능
void readWords(char norm_word[MAXSIZE], Word ** array) {
int i = 0;
bool found = false;
int result = 0;
Word * current_pointer = malloc (sizeof(Word*));//creates a temporary variable for each pointer in the array
for (i=0; i<word_counter; i++) {
current_pointer = *(array+i); //accesses the current pointer
result = strcmp(norm_word, (current_pointer -> word)); //compares the string to each stored string
if (result == 0) {
found = true;
(current_pointer->freq)++;
break;
}
}
if(!found) {
if(pointer_counter == word_counter) {
array = realloc(array, sizeof(array)*2);
pointer_counter*=2;
}
Word * new_pointer = (Word*) malloc (sizeof(Word*));
strcpy(new_pointer -> word, norm_word);
*(array + (pointer_counter - 1)) = new_pointer;
word_counter++;
}
;
}
넌 아닌 'Word' 구조, A * 포인터 *의'sizeof' 메모리 할당된다 : 여기
짧은 구현이다. 두번. – usr2564301그래서 단어 current_pointer = malloc (sizeof (char) * 512); – user48944
'sizeof (Word)'이면'예 '입니다. 나도 몰라, 당신은 샘플 코드에 포함시키지 않았다. – usr2564301