diff --git a/lcthw/.ex10.argv b/lcthw/.ex10.argv new file mode 100644 index 0000000..6c77829 --- /dev/null +++ b/lcthw/.ex10.argv @@ -0,0 +1,3 @@ +carrot +angelfood +yellow diff --git a/lcthw/.ex13.argv b/lcthw/.ex13.argv new file mode 100644 index 0000000..1c9f3d5 --- /dev/null +++ b/lcthw/.ex13.argv @@ -0,0 +1,5 @@ +garble +geckle +gimple +gorble +gunkle diff --git a/lcthw/.gitignore b/lcthw/.gitignore index 6add8a7..29a77ad 100644 --- a/lcthw/.gitignore +++ b/lcthw/.gitignore @@ -6,3 +6,4 @@ ex9 ex10 ex11 ex12 +ex13 diff --git a/lcthw/Makefile b/lcthw/Makefile index 8e85c60..8eb640d 100644 --- a/lcthw/Makefile +++ b/lcthw/Makefile @@ -1,11 +1,14 @@ CFLAGS ?= -Wall -g GDBRUN = gdb --batch --ex run --ex bt --ex q --args -BUILD_TARGETS = ex1 ex3 ex7 ex8 ex9 ex10 ex11 ex12 -TEST_TARGETS = ex1 ex3 ex7 ex8 ex9 ex11 ex12 +BUILD_TARGETS = $(foreach ex,$(wildcard ex*.c),$(subst .c,,$(ex))) .PHONY: all all: build test +.PHONY: echo +echo: + @echo BUILD_TARGETS=$(BUILD_TARGETS) + .PHONY: clean clean: rm -f $(BUILD_TARGETS) @@ -15,16 +18,18 @@ build: $(BUILD_TARGETS) .PHONY: gtest gtest: - @$(foreach bt, $(TEST_TARGETS), make .gtest.$(bt) &&) \ + @$(foreach bt, $(BUILD_TARGETS), make .gtest.$(bt) &&) \ printf '\ngYAY\n' .gtest.%: + @test_argv=$$(cat .$*.argv 2>/dev/null || echo) && \ printf '\n==> %s\n' "$*" && $(GDBRUN) ./$* .PHONY: test test: - @$(foreach bt, $(TEST_TARGETS), make .test.$(bt) &&) \ + @$(foreach bt, $(BUILD_TARGETS), make .test.$(bt) &&) \ printf '\nYAY\n' .test.%: - printf '\n==> %s\n' "$*" && ./$* + @test_argv=$$(cat .$*.argv 2>/dev/null || echo) && \ + printf '\n==> %s\n' "$*" && ./$* $$test_argv diff --git a/lcthw/ex13.c b/lcthw/ex13.c new file mode 100644 index 0000000..049c254 --- /dev/null +++ b/lcthw/ex13.c @@ -0,0 +1,25 @@ +#include + +int main(int argc, char *argv[]) +{ + int i = 0; + // go through each string in argv + // why am I skipping argv[0]? + for (i = 1; i < argc; i++) { + printf("arg %d: %s\n", i, argv[i]); + } + + // let's make our own array of strings + char *states[] = { + "California", "Oregon", + "Washington", "Texas", + }; + + int num_states = 4; + + for (i = 0; i < num_states; i++) { + printf("state %d: %s\n", i, states[i]); + } + + return 0; +}