Up through lcthw 10
This commit is contained in:
parent
94cd12ac82
commit
8f9842ddfb
1
lcthw/.gitignore
vendored
1
lcthw/.gitignore
vendored
@ -3,3 +3,4 @@ ex3
|
||||
ex7
|
||||
ex8
|
||||
ex9
|
||||
ex10
|
||||
|
@ -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
56
lcthw/ex10.c
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user