From 7da72289116f41b9ba449fcd33471cf9aa5a9d23 Mon Sep 17 00:00:00 2001 From: Dan Buch Date: Tue, 16 Apr 2024 08:03:12 -0400 Subject: [PATCH] Up through lcthw ex7 --- lcthw/.gdbinit | 1 + lcthw/.gitignore | 1 + lcthw/Makefile | 15 +++++++++++---- lcthw/ex7.c | 43 +++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 56 insertions(+), 4 deletions(-) create mode 100644 lcthw/.gdbinit create mode 100644 lcthw/ex7.c diff --git a/lcthw/.gdbinit b/lcthw/.gdbinit new file mode 100644 index 0000000..0c1f45b --- /dev/null +++ b/lcthw/.gdbinit @@ -0,0 +1 @@ +set debuginfod enabled off diff --git a/lcthw/.gitignore b/lcthw/.gitignore index 6d21d2b..f00306c 100644 --- a/lcthw/.gitignore +++ b/lcthw/.gitignore @@ -1,2 +1,3 @@ ex1 ex3 +ex7 diff --git a/lcthw/Makefile b/lcthw/Makefile index fcf2862..a0c3e2c 100644 --- a/lcthw/Makefile +++ b/lcthw/Makefile @@ -1,16 +1,23 @@ CFLAGS ?= -Wall -g +GDBRUN = gdb --batch --ex run --ex bt --ex q --args +BUILD_TARGETS = ex1 ex3 ex7 .PHONY: all all: build test .PHONY: clean clean: - rm -f ex1 ex3 + rm -f $(BUILD_TARGETS) .PHONY: build -build: ex1 ex3 +build: $(BUILD_TARGETS) + +.PHONY: gtest +gtest: + $(foreach bt,$(BUILD_TARGETS),$(GDBRUN) ./$(bt) &&) \ + echo gyay .PHONY: test test: - ./ex1 - ./ex3 + $(foreach bt,$(BUILD_TARGETS),./$(bt) &&) \ + echo yay diff --git a/lcthw/ex7.c b/lcthw/ex7.c new file mode 100644 index 0000000..1aaba2a --- /dev/null +++ b/lcthw/ex7.c @@ -0,0 +1,43 @@ +#include + +int main(int argc, char* argv[]) +{ + int distance = 100; + float power = 2.345f; + double super_power = 56789.4532; + char initial = 'A'; + char first_name[] = "Zed"; + char last_name[] = "Shaw"; + + printf("You are %d miles away.\n", distance); + printf("You have %f levels of power.\n", power); + printf("You have %f awesome super powers.\n", super_power); + printf("I have an initial %c.\n", initial); + printf("I have a first name %s.\n", first_name); + printf("I have a last name %s.\n", last_name); + printf("My whole name is %s %c. %s.\n", + first_name, initial, last_name); + + int bugs = 100; + double bug_rate = 1.2; + + printf("You have %d bugs at the imaginary rate of %f.\n", + bugs, bug_rate); + + long universe_of_defects = 1L * 1024L * 1024L * 1024L; + printf("The entire universe has %ld bugs.\n", universe_of_defects); + + double expected_bugs = bugs * bug_rate; + printf("You are expected to have %f bugs.\n", expected_bugs); + + double part_of_universe = expected_bugs / universe_of_defects; + printf("That is only a %e portion of the universe.\n", + part_of_universe); + + // this makes no sense, just a demo of something weird + char nul_byte = '\0'; + int care_percentage = bugs * nul_byte; + printf("Which means you should care %d%%.\n", care_percentage); + + return 0; +}