Up through lcthw 10

This commit is contained in:
Dan Buch 2024-04-16 21:10:41 -04:00
parent 94cd12ac82
commit 8f9842ddfb
Signed by: meatballhat
GPG Key ID: A12F782281063434
3 changed files with 61 additions and 3 deletions

1
lcthw/.gitignore vendored
View File

@ -3,3 +3,4 @@ ex3
ex7
ex8
ex9
ex10

View File

@ -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'

56
lcthw/ex10.c Normal file
View File

@ -0,0 +1,56 @@
#include <stdio.h>
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;
}