summaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authormo khan <mo.khan@gmail.com>2020-07-15 11:06:05 -0600
committermo khan <mo.khan@gmail.com>2020-07-15 11:06:05 -0600
commit67bc0208e95a61c92977031cd873c6e5ecf71b9e (patch)
tree3db27de33c7b958ed4f02166d1bc225182a487bc /main.c
parentcad5f5a17e1705c1654c51a7034950f794e2495c (diff)
Episode 2: Loops and Arrays
Diffstat (limited to 'main.c')
-rw-r--r--main.c30
1 files changed, 25 insertions, 5 deletions
diff --git a/main.c b/main.c
index a18548d..867efd6 100644
--- a/main.c
+++ b/main.c
@@ -1,14 +1,34 @@
#include <stdio.h>
+#include <string.h>
int main(int argc, char *argv[])
{
- char name[3];
+ char bike_rack[8];
+ for (int i = 0; i < 8; i = i + 1)
+ {
+ bike_rack[i] = '\0'; // NULL -> nothing
+ }
- name[0] = 'm';
- name[1] = 'o';
- name[2] = '\0';
+ // rack: [0, 1, 2, 3]
+ // mo: 'm'
+ // om: 'o'
+ // bo: 'b'
+ // yo: 'y'
- printf("%s", name);
+ bike_rack[0] = 'm';
+ /*bike_rack[1] = 'o';*/
+ /*bike_rack[2] = 'b';*/
+ bike_rack[3] = 'y';
+ for (int i = 0; i < 8; i = i + 1)
+ {
+ int bike = bike_rack[i];
+ printf("bike rack slot %d: %c\n", i, bike);
+ }
+
+ printf("\n");
return 0;
}
+
+// 1. compile: c -> machine
+// 2. run: machine -> os