~brenns10/sc-examples

ref: c9b9f2ab52ad3e30a696474c72e3dc232b436d92 sc-examples/list-example/list-example.c -rw-r--r-- 794 bytes
c9b9f2abStephen Brennan Add list example 2 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*
 * hash-tester.c: simple store or retrieve REPL to demo the hash table
 *
 * usage: hash-tester
 * > key=value
 * > key
 * value
 * > exit
 */
#define _POSIX_C_SOURCE 200809L

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "sc-collections.h"

struct argument {
	char *argstring;
	struct sc_list_head list;
};

int main(int argc, char **argv)
{
	struct sc_list_head list;
	struct argument *tmp, *next;
	int i;

	sc_list_init(&list);
	for (i = 0; i < argc; i++) {
		tmp = malloc(sizeof(struct argument));
		tmp->argstring = argv[i];
		sc_list_insert_end(&list, &tmp->list);
	}

	sc_list_for_each_entry(tmp, &list, list, struct argument) {
		printf("argument: %s\n", tmp->argstring);
	}

	sc_list_for_each_safe(tmp, next, &list, list, struct argument) {
		free(tmp);
	}
}