Up through lcthw ex7
This commit is contained in:
parent
88133117ab
commit
7da7228911
1
lcthw/.gdbinit
Normal file
1
lcthw/.gdbinit
Normal file
@ -0,0 +1 @@
|
|||||||
|
set debuginfod enabled off
|
1
lcthw/.gitignore
vendored
1
lcthw/.gitignore
vendored
@ -1,2 +1,3 @@
|
|||||||
ex1
|
ex1
|
||||||
ex3
|
ex3
|
||||||
|
ex7
|
||||||
|
@ -1,16 +1,23 @@
|
|||||||
CFLAGS ?= -Wall -g
|
CFLAGS ?= -Wall -g
|
||||||
|
GDBRUN = gdb --batch --ex run --ex bt --ex q --args
|
||||||
|
BUILD_TARGETS = ex1 ex3 ex7
|
||||||
|
|
||||||
.PHONY: all
|
.PHONY: all
|
||||||
all: build test
|
all: build test
|
||||||
|
|
||||||
.PHONY: clean
|
.PHONY: clean
|
||||||
clean:
|
clean:
|
||||||
rm -f ex1 ex3
|
rm -f $(BUILD_TARGETS)
|
||||||
|
|
||||||
.PHONY: build
|
.PHONY: build
|
||||||
build: ex1 ex3
|
build: $(BUILD_TARGETS)
|
||||||
|
|
||||||
|
.PHONY: gtest
|
||||||
|
gtest:
|
||||||
|
$(foreach bt,$(BUILD_TARGETS),$(GDBRUN) ./$(bt) &&) \
|
||||||
|
echo gyay
|
||||||
|
|
||||||
.PHONY: test
|
.PHONY: test
|
||||||
test:
|
test:
|
||||||
./ex1
|
$(foreach bt,$(BUILD_TARGETS),./$(bt) &&) \
|
||||||
./ex3
|
echo yay
|
||||||
|
43
lcthw/ex7.c
Normal file
43
lcthw/ex7.c
Normal 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;
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user