如何调用此函数进行字符串查找,然后将结果打印到屏幕上?

How do I call this function to do a string lookup and then print the result to the screen?

函数如下。我想知道如何编写用户代码来查找字符串并将字符串打印到屏幕上。

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;

您不应将字符串与 list->next 进行比较,而应将其与散列 table 条目的键进行比较。

for (list = hashtable->table[hashval]; list != NULL; list = list->next) {
    if (strcmp(str, list->string) == 0) {
        return list;
    }
    return NULL;
}