From 8f9842ddfb6b39a1141d1d44b89274e63d188f04 Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Tue, 16 Apr 2024 21:10:41 -0400 Subject: [PATCH] Up through lcthw 10 --- lcthw/.gitignore | 1 + lcthw/Makefile | 7 +++--- lcthw/ex10.c | 56 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 3 deletions(-) create mode 100644 lcthw/ex10.c diff --git a/lcthw/.gitignore b/lcthw/.gitignore index f2ef6fa..a32a055 100644 --- a/lcthw/.gitignore +++ b/lcthw/.gitignore @@ -3,3 +3,4 @@ ex3 ex7 ex8 ex9 +ex10 diff --git a/lcthw/Makefile b/lcthw/Makefile index 00d8825..989a900 100644 --- a/lcthw/Makefile +++ b/lcthw/Makefile @@ -1,6 +1,7 @@ CFLAGS ?= -Wall -g GDBRUN = gdb --batch --ex run --ex bt --ex q --args -BUILD_TARGETS = ex1 ex3 ex7 ex8 ex9 +BUILD_TARGETS = ex1 ex3 ex7 ex8 ex9 ex10 +TEST_TARGETS = ex1 ex3 ex7 ex8 ex9 .PHONY: all all: build test @@ -14,10 +15,10 @@ build: $(BUILD_TARGETS) .PHONY: gtest gtest: - @$(foreach bt,$(BUILD_TARGETS),$(GDBRUN) ./$(bt) &&) \ + @$(foreach bt,$(TEST_TARGETS),$(GDBRUN) ./$(bt) &&) \ echo ' gYAY' .PHONY: test test: - @$(foreach bt,$(BUILD_TARGETS),./$(bt) &&) \ + @$(foreach bt,$(TEST_TARGETS),./$(bt) &&) \ echo ' YAY' diff --git a/lcthw/ex10.c b/lcthw/ex10.c new file mode 100644 index 0000000..1d3d1ba --- /dev/null +++ b/lcthw/ex10.c @@ -0,0 +1,56 @@ +#include + +int main(int argc, char *argv[]) +{ + if (argc != 2) { + printf("ERROR: You need one argument.\n"); + // this is how you abort a program + return 1; + } + + int i = 0; + for (i = 0; argv[1][i] != '\0'; i++) { + char letter = argv[1][i]; + + switch (letter) { + case 'a': + case 'A': + printf("%d: 'A'\n", i); + break; + + case 'e': + case 'E': + printf("%d: 'E'\n", i); + break; + + case 'i': + case 'I': + printf("%d: 'I'\n", i); + break; + + case 'o': + case 'O': + printf("%d: 'O'\n", i); + break; + + case 'u': + case 'U': + printf("%d: 'U'\n", i); + break; + + case 'y': + case 'Y': + // why i > 2? is this a bug? + if (i > 2) { + // it's only sometimes Y + printf("%d: 'Y'\n", i); + } + break; + + default: + printf("%d: %c is not a vowel\n", i, letter); + } + } + + return 0; +}