From b6263ae4684bac6835ec0a99604bae35aadd2e71 Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 10 Jul 2016 23:27:07 -0400 Subject: [PATCH 1/2] codes for assignment 7 --- pointers.c | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ reverse.c | 29 ++++++++++++++++++++++++++ 2 files changed, 89 insertions(+) create mode 100644 pointers.c create mode 100644 reverse.c diff --git a/pointers.c b/pointers.c new file mode 100644 index 0000000..d1aabd6 --- /dev/null +++ b/pointers.c @@ -0,0 +1,60 @@ +#include +#include + +char cat(char *a, char *b){ + char *point = a; + + while(*point != '\0'){ + point ++; + } + + while (*b!= '\0'){ + *point = *b; + point ++; + b++; + } + + +} + +char comp(char *c, char *d){ + + char string1[10]; + char string2[10]; + + *c = string1[10]; + *d = string2[10]; + + int i, length1, length2; + + length1 = strlen(string1); + length2 = strlen(string2); + + + for(i=0; length1 +#include + +int reverse(char arr[]){ + char *ptr1 = arr; + + char *ptr2 = ptr1 + strlen(arr) -1; + + int i; + + for(i=0; *ptr1!=*ptr2; i++){ + printf("%c", *ptr2); + --ptr2; + } +} + +int main(){ + + char string[] = "MILICH\0"; + + reverse(string); + + return 0; + +} From 7b9cd1f4716e78a24a185d22de0712e9b372ca0e Mon Sep 17 00:00:00 2001 From: Your Name Date: Sun, 10 Jul 2016 23:27:29 -0400 Subject: [PATCH 2/2] questions --- assignment7.txt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 assignment7.txt diff --git a/assignment7.txt b/assignment7.txt new file mode 100644 index 0000000..dff1563 --- /dev/null +++ b/assignment7.txt @@ -0,0 +1,18 @@ +Aly Milich + +1. ++*p and *++p both increment the value of the array that the pointer is pointing to whereas *p++ moves the pointer over. + +2. Left to right. + +3. Pointers make it easier to use arrays to change the values of certain spots. Since you don't need the for loop, it decreases the algorithmic complexity of your code and takes up less space in the computer & is easier to run. + +4.1 char array +4.2 Invalid -- "xyz" is not in the array +4.3 Invalid -- \0 will never equal 0 +4.4 Pointer +4.5 Address is 0 +4.6 pointer +4.7 Address is still 0 +4.8 Pointer +4.9 Invalid +4.10 5