Source

randomc / main.c

#include <stdio.h>

#include "list.h"
#include "hash.h"

int main(void) {
    struct list *l = NULL, *iter = NULL;
    struct hash *h = NULL;

    l = list_init("one");
    if (l == NULL) {
        perror("failed to init list");
        return 1;
    }

    if (list_append(l, "two") == NULL) {
        perror("failed to append to list");
        return 2;
    }

    list_append(l, "three");
    list_append(l, "four");
    list_append(l, "five");
    list_append(l, "six");
    list_append(l, "seven");
    list_append(l, "eight");
    list_append(l, "nine");
    list_append(l, "ten");
    list_append(l, "11");
    list_append(l, "12");
    list_append(l, "13");
    list_append(l, "14");
    list_append(l, "15");
    list_append(l, "16");
    list_append(l, "17");
    list_append(l, "18");
    list_append(l, "19");
    list_append(l, "20");
    list_append(l, "21");
    list_append(l, "22");
    list_append(l, "23");
    list_append(l, "24");
    list_append(l, "25");

    for (iter = list_head(l); iter != NULL; iter = iter->next) {
        printf("item: %s\n", (char *)iter->data);
    }

    printf("len: %d\n", (int)list_len(l));

    list_free(list_head(l));

    h = hash_init();
    if (h == NULL) {
        perror("failed to init hash");
        return 3;
    }

    printf("get key: %s\n", (char*)hash_get(h, "key", "default"));
    hash_set(h, "key", "value");
    printf("get key: %s\n", (char*)hash_get(h, "key", "default"));
    hash_set(h, "key", "value2");
    printf("get key: %s\n", (char*)hash_get(h, "key", "default"));

    hash_free(h);

    return 0;
}