Up through lcthw ex7

This commit is contained in:
Dan Buch 2024-04-16 08:03:12 -04:00
parent 88133117ab
commit 7da7228911
Signed by: meatballhat
GPG Key ID: A12F782281063434
4 changed files with 56 additions and 4 deletions

1
lcthw/.gdbinit Normal file
View File

@ -0,0 +1 @@
set debuginfod enabled off

1
lcthw/.gitignore vendored
View File

@ -1,2 +1,3 @@
ex1
ex3
ex7

View File

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

43
lcthw/ex7.c Normal file
View File

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