I try to implement a Hash in C. The program compiles, but in the file myHash.h pulls the following warning:
warning: passing argument 1 of 'enlist' from incompatible pointer type [enabled by default]
myHash.h file
#ifndef MYHASH_H_INCLUDED
#define MYHASH_H_INCLUDED
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#define HASHMAX 10
typedef struct nodoL {
int info;
struct nodoL * sig;
} * lista;
//Definición de las Funciones
// DEFINICIÓN DE LAS FUNCIONES
//************* HASH **********
typedef lista Hash[HASHMAX];
int HashClave(int n);
void HashInsertar(Hash *H, int e);
void HashMostrar(Hash h);
void HashBuscar(Hash h,int n);
//******** LISTA *******
void enlistar (lista *L, int n);
int mostrar(lista L);/* muestra por pantalla los valores de L, en forma recursiva */
#endif // MYHASH_H_INCLUDED
All right.
File myHash.c
#include "myHash.h"
int HashClave ( int n)
{
return n%HASHMAX;
}
void HashInsertar (Hash *H, int e){
enlistar ((H)[HashClave(e)],e);
}
void enlistar (lista *L, int n){ //<--note: expected 'struct nodoL **' but argument is of type 'struct nodoL *'
lista aux = (lista)malloc(sizeof( struct nodoL ));
if(L==NULL){
aux -> info = n;
aux -> sig = *L;
*L=aux;
}
else{
if((*L)->info>n){// Para que quede ordenado
aux -> info = n;
aux -> sig = *L;
*L=aux;
}
else{
enlistar((*L)->sig,n); //<-- warning: passing argument 1 of 'enlistar' from incompatible pointer type [enabled by default]
}
}
}
int mostrar (lista L)
{
int i=0;
if(L!=NULL)
{
i=1;
printf("[%d]->",L->info);
mostrar(L->sig);
}
return i;
}
void HashMostrar(lista h){
int i, n;
for (n=0;n<HASHMAX;n++){
printf("Hash [%d]: ",n);
i=mostrar(*h);
if(i==0)printf("Lista vacia \n\n");
else printf("# \n\n");
}
}
void borrar(lista *L, char n)
{
lista aux = *L; //puntero auxiliar al primer nodo
lista ant = NULL;
if(aux==NULL)
{
printf("Error: Lista vacia");
}
else
{
while (aux->info!=n&&aux->sig!=NULL)
{
ant=aux;
aux=aux->sig;
}
if(aux->sig==NULL&&aux->info!=n)
printf("Error, caracter no se encuentra en la lista");
else
{
ant->sig=aux->sig;
free (aux); //elimino el nodo de la memoria
}
}
}
Additionally, pull the following note:
note: expected 'struct nodeL **' but argument is of type 'struct nodeL *' on the line marked.
What could be happening?