aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorErik Liodden <eriklio@stud.ntnu.no>2017-11-15 16:13:54 +0100
committerErik Liodden <eriklio@stud.ntnu.no>2017-11-15 16:13:54 +0100
commitacd916d5d87417ef362a29472189dba142ddae7a (patch)
tree5095d4ff455dfbea148fa8db182f443f52d3c7d3
parent1ec8e494716ba7b17afe752f867e9ae33e4163b0 (diff)
downloadalgdat-acd916d5d87417ef362a29472189dba142ddae7a.tar.gz
clean up main and add a separate oving.h
oving.h contains the declerations of the exercises themself. not very interesting.
-rw-r--r--include/oving.h13
-rw-r--r--src/main.c54
-rw-r--r--src/oving/oving1.c1
3 files changed, 15 insertions, 53 deletions
diff --git a/include/oving.h b/include/oving.h
new file mode 100644
index 0000000..f2b1dcf
--- /dev/null
+++ b/include/oving.h
@@ -0,0 +1,13 @@
+/*
+ * oving.h
+ * list all exercise functions
+ *
+ * Erik Liodden
+ */
+
+#ifndef OVING_H
+#define OVING_H
+
+int oving1(void);
+
+#endif /* OVING_H */
diff --git a/src/main.c b/src/main.c
index 5d1924a..19988ba 100644
--- a/src/main.c
+++ b/src/main.c
@@ -10,10 +10,7 @@
#include "list.h"
#include "io.h"
#include "options.h"
-
-int io(void);
-int llist(void);
-int oving1(void);
+#include "oving.h"
int main(int argc, char *argv[])
{
@@ -24,62 +21,13 @@ int main(int argc, char *argv[])
printf("\nTDT4120 - AlgDat - Oving %2d\n", options->oving);
printf("===========================\n\n");
}
-
switch(options->oving) {
case 1:
oving1();
break;
- case 2:
- llist();
- break;
default:
print_usage();
}
-
free(options);
-
return 0;
}
-
-int io(void)
-{
- char buf[BUF_SIZE];
- int *numbers;
- /* int numbers[BUF_SIZE]; can also be put on the stack */
- int n, i;
-
-
- read_line(buf, stdin);
- n = str_count_words(buf);
- numbers = malloc(n * sizeof(*numbers));
-
- string_to_int_array(buf, numbers);
-
- printf("number of elements: %d\n", n);
- for (i = 0; i < n; i++)
- printf("number[%d]: %d\n", i, numbers[i]);
-
- free(numbers);
- return 0;
-}
-
-int llist(void)
-{
- struct llist *list = llist_init();
- struct llist_node *node1 = malloc(sizeof(*node1));
- int a = 1;
- node1->data = &a;
-
- llist_insert_beginning(list, node1);
-
- struct llist_node *x = list->head;
- while(x != NULL) {
- printf("node: %d\n", *(int *)x->data);
- x = x->next;
- }
-
- free(node1);
- free(list);
- return 0;
-}
-
diff --git a/src/oving/oving1.c b/src/oving/oving1.c
index 7aa3ae9..2233062 100644
--- a/src/oving/oving1.c
+++ b/src/oving/oving1.c
@@ -10,6 +10,7 @@
#include <stdlib.h>
#include "list.h"
#include "io.h"
+#include "oving.h"
int oving1(void)
{