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;
}
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.