을 struct MotInfo**
안에 다시 할당하려고합니다. 이것은 나를 만든 구조체입니다. 내가하려고 할 때하지만 오류가 내 realloc
:오류 : realloc() : 유효하지 않은 포인터
int x;
MotInfo** hashtable = malloc(TAILLE*sizeof(struct MotInfo*));
for(x=0; x<TAILLE;x++)
{
hashtable[x] = NULL;
}
struct MotInfo* mot_info;
int i;
hashtable[5] = malloc(sizeof(struct MotInfo*));
mot_info = malloc(sizeof(struct MotInfo*));
mot_info->mot = "manger";
mot_info->urls = malloc(2*sizeof(char*));
mot_info->occurrences = malloc(2*sizeof(int));
mot_info->taille = 2;
for(i = 0;i<2;i++)
{
mot_info->urls[i] = "http://stackoverflow.com/questions";
mot_info->occurrences[i] = 3;
}
printf("OK\n");
hashtable[5] = mot_info;
hashtable[5]->urls = realloc(hashtable[5]->urls, sizeof(char*)*2);
내가 마지막 줄에 내 오류를 지역화,하지만 난이 오류가 :
realloc(): invalid pointer:
'해시 테이블 [5] -> urls' 이전에'malloc' 또는'에 의해 반환 된 일부 쓰레기 값 대신 포인터를 포함합니다 realloc' 또는 NULL을 리턴합니다. –
'MotInfo'의 구조 정의를 제공합니다. – Cherubim
@lurker'mot_info-> urls = malloc (...)'에 이어'hashtable [5] = mot_info'가옵니다. – Barmar