From 9fe81487b40016a93cd89106e9c2956794d89d86 Mon Sep 17 00:00:00 2001 From: Mnd2126 Date: Sun, 10 Jul 2016 13:28:30 -0400 Subject: [PATCH] Matthew Danielson - Assignment 7 --- Part2 | 34 ++++++++++++++++++++++++++++++++++ exercise.c | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ reverse.c | 27 +++++++++++++++++++++++++++ 3 files changed, 109 insertions(+) create mode 100644 Part2 create mode 100644 exercise.c create mode 100644 reverse.c diff --git a/Part2 b/Part2 new file mode 100644 index 0000000..50e2ba0 --- /dev/null +++ b/Part2 @@ -0,0 +1,34 @@ +Matthew Danielson +7/7/16 +Part 2 of Assignment7 + +1) ++*p increments the value of a pointer, and *p++ increments the address of a pointer. *++p is not valid, as it is incrementing invalidly. + +2) Left to right order is guaranteed for operator precedence; without this, many operators become essentially useless, because the logic of the code would not be reliable. + +3) Pointers are passed by reference allowing for multiple return types. Additionally, constant pointers can be made; additionally, arrays of pointers allow for non-standard char arrays that are of varying size. They can also be used to return an array of values. + +4) a[0] = 11 +a[1] = 11 +a[2] = 12 +a[3] = 13 +a[4] = 14 +a[5] = 15 +a[6] = 16 +a[7] = 17 +a[8] = 18 +a[9] = 19 +p = 12 +char *varname[] +4.1 char[] +4.2 would subtract ascii values, resulting in value 1, or SOH +4.3 Valid, changes a char +4.4 Pointer +4.5 Returns the address of the beginning of the array +4.6 Returns the value that said pointer points to +4.7 Returns the address of a pointer +4.8 Increments the address of the pointer +4.9 Gets the address of the variable +4.10 Returns an integer length of the space in memory + + diff --git a/exercise.c b/exercise.c new file mode 100644 index 0000000..a826613 --- /dev/null +++ b/exercise.c @@ -0,0 +1,48 @@ +/* Matthew Danielson +* 7/8/16 +* Pointers Practice +* name: exercise.c +*/ +#include + +int strcmp(char[], char[]); +void strct(char[], char[]); + +int main(){ + char *s1 = {"Hey"}; + char *s2 = {"all"}; + strct(s1,s2); + return 0; +} + +int strcmp(char array1[4], char array2[4]){ + int toreturn = 0; + for(int x = 0; x< 20; x++){ + if(array1[x] != array2[x]){ + if(array1[x] > array2[x]) + toreturn = -1; + if(array1[x] < array2[x]) + toreturn = 1; + break; + } + return toreturn; + } +} + +void strct(char array1[4], char array2[4]){ + char array3[sizeof(array1) + sizeof(array2)-2]; + int x = 0; + printf("%d\n", (int)sizeof(array1)); + for(; array1[x] != '\0';x++){ + array3[x] = array1[x]; + } + for(int y = 0;y + +int main(){ + int length; + char throwaway; + printf("How long will your string be?"); + scanf("%d", &length); + length ++; + scanf("%c", &throwaway); + char array[length]; + printf("\nPlease enter a string:"); + fgets(array, sizeof(array), stdin); + char *start = array; + char *end = array + sizeof(array) + 1; + while(*start != *end){ + printf("%c", *end); + *end--; + } + printf("\n"); + +}