-3
該功能列在下面。我想知道如何編寫用戶代碼來查找字符串並將字符串打印到屏幕上。如何調用此函數執行字符串查找,然後將結果輸出到屏幕?
list_t *lookup_string(hash_table *hashtable, char *str) {
list_t *list;
unsigned int hashval = hash(hashtable, str);
// go to the correct list based on the hash value and see if str is in the list. If it is, return
// a pointer to the list element. If it isn't, the item isn't in the table, so return NULL.
for (list = hashtable->table[hashval]; list != NULL; list = list->next) {
if (strcmp(str, list->next) == 0) {
return list;
}
return NULL;
}
}
下面列出了用戶定義的數據類型。
typedef struct _list_t_ {
char *string;
struct _list_t_ *next;
} list_t;
typedef struct _hash_table_t_ {
int size; //the size of the table
list_t **table; //the table elements
} hash_table;
嗯...是不是兩個相同的片段?無論如何,這個問題還不清楚。 –
即使沒有結構定義,「strcmp(str,list-> next)」也很可疑。 – EOF
...,如果懷疑「next」的確是'list_t *',應該爲不兼容的類型發出警告或錯誤。 – WhozCraig