From 442a49ad5a48d417345959b903ae6a6d32d55759 Mon Sep 17 00:00:00 2001 From: Haidong Ji Date: Fri, 15 Apr 2022 15:51:30 -0500 Subject: Great C programming fun Excellent fundamentals and displine training, many tools and techniques exercises: gdb, emacs, valgrind, git --- 13_read_arr1/.gitignore | 1 + 13_read_arr1/Makefile | 2 ++ 13_read_arr1/README | 10 ++++++++++ 13_read_arr1/answer.txt | 6 ++++++ 13_read_arr1/grade.txt | 8 ++++++++ 13_read_arr1/test.c | 21 +++++++++++++++++++++ 6 files changed, 48 insertions(+) create mode 100644 13_read_arr1/.gitignore create mode 100644 13_read_arr1/Makefile create mode 100644 13_read_arr1/README create mode 100644 13_read_arr1/answer.txt create mode 100644 13_read_arr1/grade.txt create mode 100644 13_read_arr1/test.c (limited to '13_read_arr1') diff --git a/13_read_arr1/.gitignore b/13_read_arr1/.gitignore new file mode 100644 index 0000000..9daeafb --- /dev/null +++ b/13_read_arr1/.gitignore @@ -0,0 +1 @@ +test diff --git a/13_read_arr1/Makefile b/13_read_arr1/Makefile new file mode 100644 index 0000000..c6b178d --- /dev/null +++ b/13_read_arr1/Makefile @@ -0,0 +1,2 @@ +test: test.c + gcc -o test -pedantic -std=gnu99 -Wall -Werror -lm -ggdb3 test.c diff --git a/13_read_arr1/README b/13_read_arr1/README new file mode 100644 index 0000000..bae9732 --- /dev/null +++ b/13_read_arr1/README @@ -0,0 +1,10 @@ + + 1. Execute the code in "test.c" by hand, and write the output + printed to the terminal into a file called "answer.txt" + + 2. Create a Makefile to compile test.c into a program called "test" + + 3. Run test and use its output to check your work. + + 4. Submit your Makefile and your answer.txt file. + diff --git a/13_read_arr1/answer.txt b/13_read_arr1/answer.txt new file mode 100644 index 0000000..08771c6 --- /dev/null +++ b/13_read_arr1/answer.txt @@ -0,0 +1,6 @@ +*p = 5 +Now *p = 16 +anArray[0] = 5 +anArray[1] = 42 +anArray[2] = 9 +anArray[3] = 12 diff --git a/13_read_arr1/grade.txt b/13_read_arr1/grade.txt new file mode 100644 index 0000000..0b31ec9 --- /dev/null +++ b/13_read_arr1/grade.txt @@ -0,0 +1,8 @@ +Grading at Tue 12 Oct 2021 02:57:12 AM UTC +Attempting to compile test.c +gcc -o test -pedantic -std=gnu99 -Wall -Werror -lm -ggdb3 test.c +compiled +Your file matched the expected output +Your output matched what we expected + +Overall Grade: A diff --git a/13_read_arr1/test.c b/13_read_arr1/test.c new file mode 100644 index 0000000..824b502 --- /dev/null +++ b/13_read_arr1/test.c @@ -0,0 +1,21 @@ +#include +#include + + +int main(void) { + int anArray[] = {5,16,33,99}; + int * p = anArray; + printf("*p = %d\n", *p); + p++; + printf("Now *p = %d\n", *p); + int * q = &anArray[3]; + int ** x = &q; + **x = 12; + *x = p; + **x = 42; + q[1] = 9; + for (int i =0; i < 4; i++){ + printf("anArray[%d] = %d\n",i, anArray[i]); + } + return EXIT_SUCCESS; +} -- cgit v1.2.3