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? + + + 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. + diff --git a/reverse.c b/reverse.c new file mode 100644 index 0000000..ea4faba --- /dev/null +++ b/reverse.c @@ -0,0 +1,24 @@ +#include +#include + +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; + + while(begin +#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; +} + + +