diff --git a/assignment7.txt b/assignment7.txt new file mode 100644 index 0000000..b9b296e --- /dev/null +++ b/assignment7.txt @@ -0,0 +1,25 @@ +Ava N. +July 7, 2015 + +Assignment 7 + +1. ++*p increments value at location p point to, then evaluates (stores) to incremented value. +*p++ evaluates the value at location p points to, then advances p. (*p)++ evaluates the value at the location p points to, then increments that value. + + +2. The left to right or right to left order for operator precedence is not guarenteed. + +3. The advantages of using pointers are that they provide a way for functions to modify their calling arguments, pointers support dynamic memory allocation, and they increase efficiency when working with arrays. + + +4. (*int, &char, 10, 0 or 1, ) (looking at the types: *X==y answer=o or 1 or invalid) +4.1: char * +4.2: 1 +4.3: 1 +4.4: pointer +4.5: int * +4.6: int +4.7: pointer +4.8: char* +4.9: invalid +4.10: invalid diff --git a/functions b/functions new file mode 100755 index 0000000..1b9fa0a Binary files /dev/null and b/functions differ diff --git a/reverse b/reverse new file mode 100755 index 0000000..2c1b12f Binary files /dev/null and b/reverse differ diff --git a/reverse.c b/reverse.c new file mode 100644 index 0000000..637e159 --- /dev/null +++ b/reverse.c @@ -0,0 +1,51 @@ +//Ava N. +//In a program reverse.c, write a string reversal function using pointers that takes only a string as input, creates 2 pointers, performs a string reversal using those pointers, and prints out the reversed string. Your driver should take a string input by the user using fgets(). + +#include +#include +#include + +int main(){ + char arr[50]; + char *p1; + char *p2; + char temporary; + + printf("Input a string that is under 50 letters long. \n"); + + fgets(arr, sizeof(arr), stdin); + printf("\n"); + p1 = &arr; /* points to first character in string */ + p2 = &arr[strlen(arr)-1]; /* points to last character in string */ + + +/* Diagnostic purposes ... + + printf("\nThe following is diagnostic *****\n"); + printf("You input: %s\n",arr); + printf("Sizeof(arr) is %d\n",sizeof(arr)); + printf("String Length (including null) is: %d\n",strlen(arr)); + printf("first character is: %c\n",arr[0]); + printf("last character is: %c\n",arr[strlen(arr)-2]); + printf("P1 and P2 point to char: %c %c\n",*p1,*p2); + printf("arr[0] is: %c\n",arr[0]); + printf("p1 address is %d\n",p1); + printf("p2 address is %d\n",p2); + printf("end diagnostic!**** \n\n"); +*/ +/* End diagnostic */ + + + + + while (p1 <= p2){ + temporary = *p2; + *p2 = *p1; + *p1 = temporary; + *p1++; + *p2--; + } + + printf("Here is the reversed of what you wrote: %s\n", arr); + +} diff --git a/str_functions.c b/str_functions.c new file mode 100644 index 0000000..b5f541d --- /dev/null +++ b/str_functions.c @@ -0,0 +1,26 @@ +//Ava N. +//Write a program that implements 2 functions: (strcat() and) strcmp(). Use pointers and write the main function to execute both of these function on 2 strings. + +#include +#include + +char *characters(char* var1, char* var2) { + + return characters; +} +//strcmp() +//strcat() + + +int main (){ + //int characters; + char *var1="Welcome"; + char *var2="NY!"; + + //); + //characters = strcmp(var1, var2); + + printf("Text from var1 + var2: |%s %s|\n", var1, var2); + + return(0); +}