Problema ao Passar Vetor
Não to conseguindo passar um vetor por função, ele dar este erro de compilação:
hash.c: In function ‘main’:
hash.c:44:2: warning: passing argument 2 of ‘imprimeVetor’ from incompatible pointer type [enabled by default]
In file included from hash.c:1:0:
hash.h:13:6: note: expected ‘struct Chave ’ but argument is of type ‘struct Chave ()[(sizetype)(posicoes)]’
funcoes.c: In function ‘imprimeVetor’:
funcoes.c:22:29: error: subscripted value is neither array nor pointer nor vector
Eis o código:
hash.c
#include "hash.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char** argv) {
int posicoes = 100;
Chave vet1[posicoes];
int numeroElementos = 0;
int fatorCarga = 0/100;
int i = 0;
char aux[150], *aux1;
int aux2;
FILE *fp;
if((fp = fopen( "chaves2M.txt", "r")) == NULL ) {
printf("Arquivo não encontrado\n");
exit(1);
}
Chave novo;
novo.numero = 1;
novo.string = "lala";
printf("%d %s", novo.numero, novo.string);
while(!feof(fp) && i<10){
fgets(aux,150, fp);
aux1 = strtok(aux, " ");
aux2 = atoi(strtok(NULL, " "));
novo.numero = aux2;
novo.string = (char*) malloc (150*sizeof(char));
strcpy(novo.string,aux1);
novo.prox = NULL;
vet1[hashModelo(aux1, posicoes)] = novo;
i++;
}
imprimeVetor(10, &vet1);
}
funcoes.c
#include "hash.h"
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int hashModelo(char *chav, int modulo){
int h = 0;
int n,i;
n = strlen(chav);
for(i=0;i<n;i++){
h += chav[i]*31*n;
}
return h%modulo;
}
//funcao hash que utiliza as strings para formar uma, adicionado o modulo para se adaptar ao tamanho da tabela.
void imprimeVetor(int maximo, Chave *vet){
int i =0;
for(i=0;i<maximo;i++){
printf("%d\n", vet->numero[i]);
}
}
//funcao pra imprimir o valor com um maximo pré-determinado, para testes apenas.
hash.h
#ifndef HASH_H
#define HASH_H
typedef struct chave {
int numero;
char *string;struct chave *prox; // será usado para o tratamento de colisão encadeado
} Chave;
#endif
void imprimeVetor(int maximo, Chave *vet);
int hashModelo(char *chav, int modulo);
To trancado nisso há dias já :(
É no imprimeVetor.
Discussão (2)
Carregando comentários...