aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoraindros <aindros@hotmail.com>2020-01-08 22:11:47 +0100
committeraindros <aindros@hotmail.com>2020-01-08 22:11:47 +0100
commitd62f358393ba80825bb340a96be789ba314e3960 (patch)
treec4166dede6e543d0e11d5aae260046728172c2d3 /src
parent50928935b894acb32916bf971d719428cf19ac8c (diff)
downloadutils-d62f358393ba80825bb340a96be789ba314e3960.tar.gz
utils-d62f358393ba80825bb340a96be789ba314e3960.zip
src
Diffstat (limited to 'src')
-rw-r--r--src/list.c34
-rw-r--r--src/list.h16
-rw-r--r--src/main.c19
3 files changed, 69 insertions, 0 deletions
diff --git a/src/list.c b/src/list.c
new file mode 100644
index 0000000..561b308
--- /dev/null
+++ b/src/list.c
@@ -0,0 +1,34 @@
+#include <stdlib.h>
+#include "list.h"
+
+/*
+ * Creates a new list.
+ */
+List* List_Create(void)
+{
+ List* list = malloc(sizeof(List));
+
+ list->next = NULL; /* nwxt element is empty */
+ list->current = list; /* points to itself */
+ list->first = list; /* first element is itself */
+ list->data = NULL; /* data is empty */
+ list->size = 0;
+
+ return list;
+}
+
+/*
+ * Adds a new element to the list.
+ */
+void List_Add(List* list, /* list where to add new element */
+ void* data, /* data to add */
+ int size_of) /* size of the data */
+{
+ void* dest = malloc(size_of); /* allocates memory like data parameter */
+
+ memcpy(dest, data, size_of); /* copies data inside dest */
+ list->data = dest;
+
+ list->next = malloc(sizeof(List));
+ list->size ++;
+}
diff --git a/src/list.h b/src/list.h
new file mode 100644
index 0000000..083e239
--- /dev/null
+++ b/src/list.h
@@ -0,0 +1,16 @@
+#ifndef _LIST_H_
+#define _LIST_H_
+
+typedef struct list_t {
+ void* data;
+ struct List* next;
+ struct List* first;
+ struct List* current;
+ int size;
+} List;
+
+List* List_Create(void);
+void List_Add (List*, void*, int);
+void List_Remove();
+
+#endif
diff --git a/src/main.c b/src/main.c
new file mode 100644
index 0000000..9361ae6
--- /dev/null
+++ b/src/main.c
@@ -0,0 +1,19 @@
+#include <stdio.h>
+#include "list.h"
+
+int main(int argc, char** argv)
+{
+ int test1 = 5;
+ int test2 = 32;
+
+ List* list = List_Create();
+
+ List_Add(list, &test1, sizeof(int));
+ List_Add(list, &test2, sizeof(int));
+
+ int* t = list->data;
+
+ printf("Valore: %i, size: %i\n", *t, list->size);
+
+ return 0;
+}