diff options
author | standenboy <standenboy@seacrossedlovers.xyz> | 2024-04-25 08:45:36 +0100 |
---|---|---|
committer | standenboy <standenboy@seacrossedlovers.xyz> | 2024-04-25 08:45:36 +0100 |
commit | 7d3856203d28281e3ffc6b365cc55b1d192a5599 (patch) | |
tree | 226ffda231a717f625bd1a965a32d02d0d1348b0 /comp/cw/code/tokenizer/ads/dict | |
parent | a241ad8e874a2220d81254c2ebfbe69d0470fd9b (diff) |
started cw
Diffstat (limited to 'comp/cw/code/tokenizer/ads/dict')
-rw-r--r-- | comp/cw/code/tokenizer/ads/dict/Makefile | 4 | ||||
-rw-r--r-- | comp/cw/code/tokenizer/ads/dict/dict.c | 29 | ||||
-rw-r--r-- | comp/cw/code/tokenizer/ads/dict/dict.h | 9 | ||||
-rw-r--r-- | comp/cw/code/tokenizer/ads/dict/dict.o | bin | 0 -> 1768 bytes | |||
-rwxr-xr-x | comp/cw/code/tokenizer/ads/dict/dicttest | bin | 0 -> 20536 bytes | |||
-rw-r--r-- | comp/cw/code/tokenizer/ads/dict/dicttest.c | 10 |
6 files changed, 52 insertions, 0 deletions
diff --git a/comp/cw/code/tokenizer/ads/dict/Makefile b/comp/cw/code/tokenizer/ads/dict/Makefile new file mode 100644 index 0000000..f224267 --- /dev/null +++ b/comp/cw/code/tokenizer/ads/dict/Makefile @@ -0,0 +1,4 @@ +all: dict.c + cc dict.c -c -o dict.o +test: all + cc dict.o dicttest.c -o dicttest diff --git a/comp/cw/code/tokenizer/ads/dict/dict.c b/comp/cw/code/tokenizer/ads/dict/dict.c new file mode 100644 index 0000000..551afca --- /dev/null +++ b/comp/cw/code/tokenizer/ads/dict/dict.c @@ -0,0 +1,29 @@ +#include <stdlib.h> +#include <string.h> + +typedef struct dict_t { + int id; + void *data; +}dict_t; + +dict_t *dictalloc(){ + dict_t *output = malloc(sizeof(dict_t)); + return output; +} + +int dictset(dict_t *dict, int id, void *data){ + dict->id = id; + + dict->data = malloc(sizeof(data)); + if (dict->data == NULL) + return 1; + memcpy(dict->data, data, sizeof(data)); + + return 0; +} + +void dictfree(dict_t *dict){ + free(dict->data); + free(dict); +} + diff --git a/comp/cw/code/tokenizer/ads/dict/dict.h b/comp/cw/code/tokenizer/ads/dict/dict.h new file mode 100644 index 0000000..e6ab69d --- /dev/null +++ b/comp/cw/code/tokenizer/ads/dict/dict.h @@ -0,0 +1,9 @@ +typedef struct dict_t { + int id; + void *data; +}dict_t; + +dict_t *dictalloc(); +int dictset(dict_t *dict, int id, void *data); +void dictfree(dict_t *dict); + diff --git a/comp/cw/code/tokenizer/ads/dict/dict.o b/comp/cw/code/tokenizer/ads/dict/dict.o Binary files differnew file mode 100644 index 0000000..aefd77a --- /dev/null +++ b/comp/cw/code/tokenizer/ads/dict/dict.o diff --git a/comp/cw/code/tokenizer/ads/dict/dicttest b/comp/cw/code/tokenizer/ads/dict/dicttest Binary files differnew file mode 100755 index 0000000..dddf2a0 --- /dev/null +++ b/comp/cw/code/tokenizer/ads/dict/dicttest diff --git a/comp/cw/code/tokenizer/ads/dict/dicttest.c b/comp/cw/code/tokenizer/ads/dict/dicttest.c new file mode 100644 index 0000000..4a20870 --- /dev/null +++ b/comp/cw/code/tokenizer/ads/dict/dicttest.c @@ -0,0 +1,10 @@ +#include <stdio.h> + +#include "dict.h" + +int main(){ + dict_t *dict = dictalloc(); + dictset(dict, 1, "hello"); + printf("%d:%s\n", dict->id, (char *)dict->data); + dictfree(dict); +} |