summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--wk5/lect/list2.c33
-rw-r--r--wk5/lect/temp.c2
2 files changed, 35 insertions, 0 deletions
diff --git a/wk5/lect/list2.c b/wk5/lect/list2.c
new file mode 100644
index 0000000..7da5a5b
--- /dev/null
+++ b/wk5/lect/list2.c
@@ -0,0 +1,33 @@
+#include <cs50.h>
+#include <ctype.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+
+typedef struct node
+{
+ int number;
+ struct node *next;
+} node;
+
+int main(int argc, char *argv[])
+{
+ node *list = NULL;
+
+ for (int i = 1; i < argc; i++)
+ {
+ int number = atoi(argv[i]);
+
+ node *n = malloc(sizeof(node));
+ if (n == NULL)
+ {
+ // free memory
+ return 1;
+ }
+
+ n->number = number;
+ n->
+ }
+}
diff --git a/wk5/lect/temp.c b/wk5/lect/temp.c
index 6c83fc4..b5f75c7 100644
--- a/wk5/lect/temp.c
+++ b/wk5/lect/temp.c
@@ -22,5 +22,7 @@ int main(void)
node *n = malloc(sizeof(node));
n->number = 2;
n->next = list;
+ list = n;
+ // This creates a linked list where 2 points to 1
}