Hey hey,
I am trying to wrap my head around C right now (mostly how pointers operate). I am trying to write this function described below:
/* EnterName enter a Name into a symbol table. Returns a boolean indicating whether an entry for Name was already listed in the table. Passes back an argument containing an entry reference for the name.
Anyway, here is the code I have written and I am not sure how to test it at the moment. Wondering if someone could look over it and let me know if I am doing this right.
Thanks in advance.
Code::
bool EnterName(struct SymTab *ATable,
const char *Name,
struct SymEntry * *AnEntry)
{
char name = *Name;
unsigned hashval = hash (&name);
struct SymEntry *ptr;
ptr = ATable->Contents[hashval];
while(ptr != NULL)
{
if(strcmp(ptr->Name, &name))
{
AnEntry = &ptr;
return true;
}
}
ptr = malloc(sizeof(struct SymEntry));
ptr->Name = &name;
AnEntry = &ptr;
return false;
}