summaryrefslogtreecommitdiff
path: root/17_read_arr2
diff options
context:
space:
mode:
authorHaidong Ji2022-04-15 15:51:30 -0500
committerHaidong Ji2022-04-15 15:51:30 -0500
commit442a49ad5a48d417345959b903ae6a6d32d55759 (patch)
treec7127bb497e5e439018b1915e0136eec2c9cb124 /17_read_arr2
Great C programming funHEADmaster
Excellent fundamentals and displine training, many tools and techniques exercises: gdb, emacs, valgrind, git
Diffstat (limited to '17_read_arr2')
-rw-r--r--17_read_arr2/.gitignore1
-rw-r--r--17_read_arr2/Makefile2
-rw-r--r--17_read_arr2/README12
-rw-r--r--17_read_arr2/answer.txt8
-rw-r--r--17_read_arr2/grade.txt8
-rw-r--r--17_read_arr2/test.c27
6 files changed, 58 insertions, 0 deletions
diff --git a/17_read_arr2/.gitignore b/17_read_arr2/.gitignore
new file mode 100644
index 0000000..9daeafb
--- /dev/null
+++ b/17_read_arr2/.gitignore
@@ -0,0 +1 @@
+test
diff --git a/17_read_arr2/Makefile b/17_read_arr2/Makefile
new file mode 100644
index 0000000..f337094
--- /dev/null
+++ b/17_read_arr2/Makefile
@@ -0,0 +1,2 @@
+test: test.c
+ gcc -o test -pedantic -std=gnu99 -Wall -Werror test.c
diff --git a/17_read_arr2/README b/17_read_arr2/README
new file mode 100644
index 0000000..bcdb734
--- /dev/null
+++ b/17_read_arr2/README
@@ -0,0 +1,12 @@
+ 1. Execute the code in "test.c" by hand, and write the output
+ into a file called "answer.txt"
+
+ Hint: you may need to consult the man pages for functions
+ that you are not familiar with.
+
+ 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 answer.txt
+
diff --git a/17_read_arr2/answer.txt b/17_read_arr2/answer.txt
new file mode 100644
index 0000000..93250fc
--- /dev/null
+++ b/17_read_arr2/answer.txt
@@ -0,0 +1,8 @@
+p
+l
+n
+a
+bannana has nana 3 characters into it!
+r
+o
+fduurw
diff --git a/17_read_arr2/grade.txt b/17_read_arr2/grade.txt
new file mode 100644
index 0000000..d949c21
--- /dev/null
+++ b/17_read_arr2/grade.txt
@@ -0,0 +1,8 @@
+Grading at Fri 15 Oct 2021 02:08:49 AM UTC
+Attempting to compile test.c
+gcc -o test -pedantic -std=gnu99 -Wall -Werror test.c
+compiled
+Your file matched the expected output
+Your output matched what we expected
+
+Overall Grade: A
diff --git a/17_read_arr2/test.c b/17_read_arr2/test.c
new file mode 100644
index 0000000..e0b30b0
--- /dev/null
+++ b/17_read_arr2/test.c
@@ -0,0 +1,27 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#define NSTRS 3
+int main(void) {
+ const char * strs[NSTRS] = {"apple", "bannana", "carrot"};
+
+ for (int i = 0; i < NSTRS; i++) {
+ const char * a = strchr(strs[i], 'a');
+ a++;
+ printf("%c\n", *a);
+ printf("%c\n", a[2]);
+ a = strstr(strs[i], "nana");
+ if (a != NULL) {
+ printf("%s has %s %ld characters into it!\n", strs[i], a, a - strs[i]);
+ }
+ }
+ const char * ptr = strs[2];
+ while (*ptr != '\0') {
+ char x = *ptr + 3;
+ printf("%c", x);
+ ptr++;
+ }
+ printf("\n");
+ return EXIT_SUCCESS;
+}