I need to use the following structures without changing their implementations from a .h
file.
typedef unsigned long int chave_t;
typedef unsigned long int conteudo_t;
typedef struct entrada_hash{
chave_t chave;
conteudo_t * conteudo;
struct entrada_hash * proximo;
} entrada_hash_t;
typedef struct elemento_lista{
entrada_hash_t * elemento;
struct elemento_lista * proximo;
} elemento_lista_t;
typedef struct tabela_hash{
unsigned long int numero_elementos;
struct entrada_hash_t * armazenamento;
void * sincronizacao;
} hash_t;
However when initializing the hash table and trying to access any of the contents placed in your input I get the following error:
hash_s.c: In function ‘ht_init’:
hash_s.c:18:3: error: invalid use of undefined type ‘struct entrada_hash_t’
hash->armazenamento[i]->chave = i;
^
hash_s.c:18:22: error: dereferencing pointer to incomplete type
hash->armazenamento[i]->chave = i;
^
Initializing the variables I do as follows:
hash_t * ht_init(unsigned long tam) {
hash_t * hash ;
unsigned long i = 0;
hash = malloc(sizeof(hash_t));
hash->numero_elementos = tam;
hash->armazenamento = malloc (tam * sizeof(entrada_hash_t));
for(i=0;i<tam;i++){
hash->armazenamento[i]->chave = i;
}
return hash;
}
First I had thought that the structures were not being imported from the .h file, but if that were the way the compiler would already give me an error trying to declare them previously to for
. So I guess I'm not assigning something needed at some point inside the init_t
function, can anyone see what's wrong?