|
-
October 10th, 2009, 01:02 PM
#1
I need help with C errors :-\ please
I was hoping you could help me out with a bug that I cant figure out :-\.
Im getting an error saying "passes.c:99: error: incompatible types in assignment" for my line
" *cur = malloc(sizeof(struct label_address_pair)); "
I defined cur as
" struct label_address_pair *cur = hashtable[hashVal]; "
and hashtable is just an array of label_address_pair.
That line defining *cur however also has an error saying:
" passes.c:92: error: incompatible types in initialization "
... any clues as to what is wrong here? It makes sense to me because im just allocating space for my pointer variable, yet its saying incompatible types. When i get take away the * from *cur, the error goes away...
Thanks, Sean.
P.S. if you need more code, heres more with it in context:
struct label_address_pair{
char *label;
unsigned int address;
struct label_address_pair *next;
};
int outputLength = 0;
//hashtable
int tblLen = 1009;
struct label_address_pair hashtable[1009];
unsigned long hash( char *str, int tableLength )
{
unsigned long hash = 5381;
int c;
while( (c = *str++) )
{
hash = ((hash << 5 ) + hash ) + c;
}
return hash % tableLength;
}
int first_pass_process_label(int line, char *label)
{
if( label == NULL ){ printf("passed in character is null."); exit(-1); }
long hashVal = hash( label, tblLen );
struct label_address_pair *cur = hashtable[hashVal];
while( cur != NULL)
{
cur = cur->next;
}
*cur = malloc(sizeof(struct label_address_pair));
cur->label = malloc( strlen( label) +1 );
strcpy(cur->label, label);
cur->address = outputLength;
cur->next = NULL;
return 0;
}
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|