From 394899559a76900e370ad55d3fe682324fe1e952 Mon Sep 17 00:00:00 2001 From: Sheqi Date: Fri, 8 Jul 2016 09:29:47 -0400 Subject: [PATCH 1/5] reverse.c --- reverse.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 reverse.c diff --git a/reverse.c b/reverse.c new file mode 100644 index 0000000..cdad811 --- /dev/null +++ b/reverse.c @@ -0,0 +1,25 @@ +#include +#include + +void recursive(char* begin){ + char* end; + char a; + + end=begin+strlen(begin)-1; + + while(begin Date: Fri, 8 Jul 2016 15:58:17 -0400 Subject: [PATCH 2/5] Assignment7 --- Assignment7 Sheqi.out | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 Assignment7 Sheqi.out diff --git a/Assignment7 Sheqi.out b/Assignment7 Sheqi.out new file mode 100644 index 0000000..31ce7d9 --- /dev/null +++ b/Assignment7 Sheqi.out @@ -0,0 +1,42 @@ +Assignment 7 Sheqi Zhang + +1. Explain the difference between ++*p, *p++ and *++p, if there is any. +Answer: +++*p increments the value at location p points to, then evaluates to incremented value. +*p++ evaluates the value at location p points to, then advances p. +*++p increments the value of p, then evaluate the location ++p points to. + +2. Is the left to right or right to left order guaranteed for operator precedence? +Answer: +In most situations, the left to right order is guarenteed, while for operators like "+=","-=", the order is right to left. + +3. What is the advantage of using pointers? +Answer: +The pointer provide a way for functions to modify their calling argument, and it supports the dynamic memory allocation. It's more effecient comparing with arrays. + +4. + 4.1 "abc"
+ char + 4.2 "xyz"[1] - ’y’
+ Invalid. "xyz"[1] is an array, while 'y' is character; + 4.3 ’\0’ == 0
+ boolean. It is judging if it's wrong. + 4.4 *a
+ pointer. Because there is a "*" in front of "a". + 4.5 &a[0]
+ pointer or array. + It can be the array in the scanf function, it can also be the pointer of the variable a[0]. + 4.6 *p
+ pointer. Because there is a "*" in front of "p". + 4.7 &p
+ pointer or variable. + Because there is a "&", it may be a pointer. While it can also be a variable in the scanf function. + 4.8 *++argv
+ pointer. Because there is a "*". + 4.9 &main
+ Because there is a "&", it may be a pointer. While it can also be a variable in the scanf function. + 4.10 sizeof(str)
+ Integer. The value is the length of str. 3? + + + From a2556f99bdd74400466020e705e4f316a5ad5d2d Mon Sep 17 00:00:00 2001 From: Sheqi Date: Fri, 8 Jul 2016 18:28:28 -0400 Subject: [PATCH 3/5] reverse.c --- reverse.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/reverse.c b/reverse.c index cdad811..ea4faba 100644 --- a/reverse.c +++ b/reverse.c @@ -1,25 +1,24 @@ #include #include -void recursive(char* begin){ +int main(){ + char string[20]; + printf("Please enter a string within 20 characters:\n"); + fgets(string,sizeof(string),stdin); + char* begin; char* end; char a; + begin=string; + end= begin + strlen(string)-1; - end=begin+strlen(begin)-1; - while(begin Date: Mon, 11 Jul 2016 08:44:08 -0400 Subject: [PATCH 4/5] strings.c --- strings.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 strings.c diff --git a/strings.c b/strings.c new file mode 100644 index 0000000..1b63e9d --- /dev/null +++ b/strings.c @@ -0,0 +1,39 @@ +#include +#include +#include + +char* strcpy(char*s1,const char*s2){ + assert((s1!=NULL)&&(s2!=NULL)); + char*ret=s1; + while((*s1++==*s2++)!='\0'); + return ret; +} + +char* strcat(char*s1,const char*s2){ + char* address=s1; + assert((s1!=NULL)&&(s2!=NULL)); + while(*s1) + { + s1++; + } + while(*s1==*s2) + { + NULL; + } + return address; +} + +int main(){ + char* s1; + const char* s2; + printf("Please type in the first sentence:\n"); + scanf("%s",&s1); + printf("Please type in the second sentence:\n"); + scanf("%s",&s2); + printf("%s",strcpy(s1,s2)); + printf("%s",strcat(s1,s2)); + return 0; +} + + + From dca844ae915a450de47d1d15bc2a9f3c190db20d Mon Sep 17 00:00:00 2001 From: Sheqi Date: Mon, 11 Jul 2016 09:20:03 -0400 Subject: [PATCH 5/5] final project proposal Sheqi --- Final Project Proposal | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 Final Project Proposal diff --git a/Final Project Proposal b/Final Project Proposal new file mode 100644 index 0000000..04485c2 --- /dev/null +++ b/Final Project Proposal @@ -0,0 +1,33 @@ +Proposal of Final Project Sheqi + +My plan is to write a program that can calculate the frequency of the words appearing in a document. + +I want to do this because I think it's useful, and I believe the most important characteristic of computer programming is useful. In addition, I can almost handle it with the things I have learend in the summer program. + +Steps: +1. Open document 1 and read it, and judge if it opens successfully at the same time. +2. If open successfully, as well as not reaching the end of the document, then calculate the frequency of a word. +3. Repeat step 2 till the end of the document. +4. Close document 1. +5. Open document 2 and try to record data on it, and judge if it opens successfully at the same time. +6. If open successfully, then record all the words and their frequencies in this document. +7. Close document 2. +8. Make all words fit in a static order (maybe from "a" to "z"). +9. Open document 3 and try to record data in it, and judge if it opens successfully at the same time. +10. If open successfully, then record all the words and frequencies in the order in document 3. +11. Close document 3. + +How to use loops: +During the process calculating the frequency of one word. +How to use advanced datatypes: +Use structures to combine the words and their frequencies together. +How to use functions: +.... +How to use arrays: +In the process of calculating the frequency of one word. +Arrays: +In the structure. + +External Library: +I don't understand what is an external library, but I can find external help from my mom. She is a professor in Tsinghua University teaching computer linguistics. +