Up through lcthw 11

This commit is contained in:
Dan Buch 2024-04-17 08:22:20 -04:00
parent 353b77271d
commit 1a894440f9
Signed by: meatballhat
GPG Key ID: A12F782281063434
3 changed files with 61 additions and 6 deletions

1
lcthw/.gitignore vendored
View File

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

View File

@ -1,7 +1,7 @@
CFLAGS ?= -Wall -g CFLAGS ?= -Wall -g
GDBRUN = gdb --batch --ex run --ex bt --ex q --args GDBRUN = gdb --batch --ex run --ex bt --ex q --args
BUILD_TARGETS = ex1 ex3 ex7 ex8 ex9 ex10 BUILD_TARGETS = ex1 ex3 ex7 ex8 ex9 ex10 ex11
TEST_TARGETS = ex1 ex3 ex7 ex8 ex9 TEST_TARGETS = ex1 ex3 ex7 ex8 ex9 ex11
.PHONY: all .PHONY: all
all: build test all: build test
@ -15,10 +15,16 @@ build: $(BUILD_TARGETS)
.PHONY: gtest .PHONY: gtest
gtest: gtest:
@$(foreach bt,$(TEST_TARGETS),$(GDBRUN) ./$(bt) &&) \ @$(foreach bt, \
echo ' gYAY' $(TEST_TARGETS), \
printf '\n==> $(bt)\n' && $(GDBRUN) ./$(bt) && \
) \
printf '\ngYAY\n'
.PHONY: test .PHONY: test
test: test:
@$(foreach bt,$(TEST_TARGETS),./$(bt) &&) \ @$(foreach bt, \
echo ' YAY' $(TEST_TARGETS), \
printf '\n==> %s\n' "$(bt)" && ./$(bt) && \
) \
printf '\nYAY\n'

48
lcthw/ex11.c Normal file
View File

@ -0,0 +1,48 @@
#include <stdio.h>
int main(int argc, char *argv[])
{
int numbers[4] = { 0 };
char name[4] = { 'a' };
// first, print them out raw
printf("numbers: %d %d %d %d\n",
numbers[0], numbers[1], numbers[2], numbers[3]);
printf("name each: %c %c %c %c\n",
name[0], name[1], name[2], name[3]);
printf("name: %s\n", name);
// setup the numbers
numbers[0] = 1;
numbers[1] = 2;
numbers[2] = 3;
numbers[3] = 4;
// setup the name
name[0] = 'Z';
name[1] = 'e';
name[2] = 'd';
name[3] = '\0';
// then print them out initialized
printf("numbers: %d %d %d %d\n",
numbers[0], numbers[1], numbers[2], numbers[3]);
printf("name each: %c %c %c %c\n",
name[0], name[1], name[2], name[3]);
// print the name like a string
printf("name: %s\n", name);
// another way to use name
char *another = "Zed";
printf("another: %s\n", another);
printf("another each: %c %c %c %c\n",
another[0], another[1], another[2], another[3]);
return 0;
}