So, I'm having a little problem. I'm trying to build a hash table, but I keep getting an error saying "return from incompatible pointer type." I know what this means, but I don't know why my code isn't working. I'm looking for an explanation of why my code does not work. Why does it not recognize the array as a pointer?
I'm making an array of pointers to structs for a hash table. (externally chained) (I know that my code probably really sucks >< I'm still learning!)
struct hashTBL {
char *userID;
char *password;
struct hashTBL *next;
};
typedef struct hashTBL Tbl;
typedef struct hashTBL* TblPTR;
TblPTR createHashTBL(int size)
{
char *userID;
char *password;
int i;
TblPTR hashArray[size];
FILE* fpData;
char *fileName = "encrypted.txt";
fpData = openReadFile(fileName);
TblPTR T = NULL;
while((fscanf(fpData, "%s", userID)) != EOF)
{
fscanf(fpData, "%s", password);
i = hash(userID, size);
if(hashArray[i] != NULL)
{
TblPTR H = hashArray[i];
while(H != NULL)
{
T = H;
H = H->next;
}
H = newPTR(userID, password, T);
}
else
{
hashArray[i] = newPTR(userID, password, T);
}
}
closeFile(fpData);
return &hashArray;
}
TblPTR newPTR(char *userID, char *password, TblPTR T)
{
TblPTR H = (TblPTR)malloc(sizeof(Tbl));
if(T != NULL) T->next = H;
H->userID = userID;
H->password = password;
H->next = NULL;
return H;
}
TblPTRis a typedef forTbl*, but you didn't supply the definition ofTbl.