diff options
Diffstat (limited to 'hw3')
| -rw-r--r-- | hw3/2620.HW03.Data Structures.docx | bin | 0 -> 20153 bytes | |||
| -rw-r--r-- | hw3/Capture.PNG | bin | 0 -> 98482 bytes | |||
| -rw-r--r-- | hw3/a.exe | bin | 0 -> 322503 bytes | |||
| -rw-r--r-- | hw3/hw3.odt | bin | 0 -> 117182 bytes | |||
| -rw-r--r-- | hw3/hw3.zip | bin | 0 -> 19393 bytes | |||
| -rw-r--r-- | hw3/karate2.ods | bin | 0 -> 35475 bytes | |||
| -rw-r--r-- | hw3/problem1.c | 17 | ||||
| -rw-r--r-- | hw3/problem2.c | 32 | ||||
| -rw-r--r-- | hw3/problem3.c | 5 | ||||
| -rw-r--r-- | hw3/problem4.c | 17 | ||||
| -rw-r--r-- | hw3/problem5.c | 61 |
11 files changed, 132 insertions, 0 deletions
diff --git a/hw3/2620.HW03.Data Structures.docx b/hw3/2620.HW03.Data Structures.docx Binary files differnew file mode 100644 index 0000000..6d82261 --- /dev/null +++ b/hw3/2620.HW03.Data Structures.docx diff --git a/hw3/Capture.PNG b/hw3/Capture.PNG Binary files differnew file mode 100644 index 0000000..f46465a --- /dev/null +++ b/hw3/Capture.PNG diff --git a/hw3/a.exe b/hw3/a.exe Binary files differnew file mode 100644 index 0000000..22daa30 --- /dev/null +++ b/hw3/a.exe diff --git a/hw3/hw3.odt b/hw3/hw3.odt Binary files differnew file mode 100644 index 0000000..4c6907f --- /dev/null +++ b/hw3/hw3.odt diff --git a/hw3/hw3.zip b/hw3/hw3.zip Binary files differnew file mode 100644 index 0000000..28f5f8f --- /dev/null +++ b/hw3/hw3.zip diff --git a/hw3/karate2.ods b/hw3/karate2.ods Binary files differnew file mode 100644 index 0000000..27c9154 --- /dev/null +++ b/hw3/karate2.ods diff --git a/hw3/problem1.c b/hw3/problem1.c new file mode 100644 index 0000000..784b570 --- /dev/null +++ b/hw3/problem1.c @@ -0,0 +1,17 @@ +#include <stdio.h> + +void getString(char *in, int buffer){ + char *c = in; + for(; c < in + buffer; c++){ + *c = getchar(); + if(*c == EOF) + break; + } + *c = '\0'; +} + +int main(){ + char test[256]; + getString(test,100); + printf("Got string: %s\n", test); +} diff --git a/hw3/problem2.c b/hw3/problem2.c new file mode 100644 index 0000000..3c345b3 --- /dev/null +++ b/hw3/problem2.c @@ -0,0 +1,32 @@ +#include <string.h> +#include <stdio.h> +#include <stdlib.h> + +int string2array(char *inString, char **wordarray){ + const char whitespace[] = " "; + char **cursor = wordarray; + int ret = 0; + char *this = NULL; + while(1){ + this = strtok(inString,whitespace); + if(this == NULL) + break; + char *dest = strcpy(wordarray[ret],this); + inString = NULL; + ret++; + } + return ret; +} + +int main(){ + char instring[] = "This is a string that needs to be split"; + char **wordarray = (char**) malloc(sizeof(char*) * 20); + for(int i = 0; i < 20; i++){ + wordarray[i] = (char*)malloc(sizeof(char) * 100); + } + string2array(instring,(char**)wordarray); + printf("wordarray ended up being:\n"); + for(int i = 0; i < 20; i++) + printf("%d: %s\n",i,wordarray[i]); + +} diff --git a/hw3/problem3.c b/hw3/problem3.c new file mode 100644 index 0000000..716915f --- /dev/null +++ b/hw3/problem3.c @@ -0,0 +1,5 @@ +#include <ctype.h> + +void proper(char *word){ + word[0] = toupper(word[0]); +} diff --git a/hw3/problem4.c b/hw3/problem4.c new file mode 100644 index 0000000..3b1ad43 --- /dev/null +++ b/hw3/problem4.c @@ -0,0 +1,17 @@ +#include <stdio.h> + +void printArray(char **words, int wordcount){ + for(int i = 0; i < wordcount; i++) + printf("%s\n",words[i]); +} + +int main(){ + char *words[] = { + "This", + "Is", + "a", + "test", + }; + printArray(words,4); +} + diff --git a/hw3/problem5.c b/hw3/problem5.c new file mode 100644 index 0000000..4af17d1 --- /dev/null +++ b/hw3/problem5.c @@ -0,0 +1,61 @@ +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <ctype.h> + +void printArray(char **words, int wordcount){ + for(int i = 0; i < wordcount; i++) + printf("%s\n",words[i]); +} +void proper(char *word){ + word[0] = toupper(word[0]); +} +int string2array(char *inString, char **wordarray){ + const char whitespace[] = " "; + char **cursor = wordarray; + int ret = 0; + char *this = NULL; + while(1){ + this = strtok(inString,whitespace); + if(this == NULL) + break; + char *dest = strcpy(wordarray[ret],this); + inString = NULL; + ret++; + } + return ret; +} +void getString(char *in, int buffer){ + char *c = in; + for(; c < in + buffer; c++){ + *c = getchar(); + if(*c == EOF) + break; + } + *c = '\0'; +} + +struct Sentence { + char string[50]; + char *words[10]; + int wordCount; +}; + +/* + a. Store input into the sentence string, + b. Parse the string into an array of words and store the number of words found, + c. Proper case each word in the sentence, + d. and print out the proper cased sentence +*/ +int main(int argc, char **argv){ + struct Sentence s; + for(int i = 0; i < 10; i++) + s.words[i] = malloc(sizeof(char) * 50); + s.wordCount = 0; + getString(s.string,50); + s.wordCount = string2array(s.string, s.words); + for(int i = 0; i < 10; i++) + proper(s.words[i]); + printArray(s.words,s.wordCount); + return 0; +} |
