From 5594497fb548e9496d0ce769cf9bd7c54a975dbc Mon Sep 17 00:00:00 2001 From: k Date: Fri, 1 Jul 2016 15:39:11 -0400 Subject: [PATCH 1/5] Array 1? --- array1.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 array1.c diff --git a/array1.c b/array1.c new file mode 100644 index 0000000..6f58e7b --- /dev/null +++ b/array1.c @@ -0,0 +1,14 @@ +#include + +int main(){ + int x; + int sum=0; + printf("How many numbers are you inputing? \n"); + scanf("%d", &x); + int array[x]; + for(x=x-1;x>=0;x--){ + scanf("%d",&array[x]); + sum=sum+array[x]; + } + printf("The Sum is: %d \n" , sum); +} From 9df24d6d3ce1649a8f299fdf49363a7e961855c9 Mon Sep 17 00:00:00 2001 From: k Date: Mon, 4 Jul 2016 11:11:12 -0400 Subject: [PATCH 2/5] Counting Frequency in String by Oscar So --- string1.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 string1.c diff --git a/string1.c b/string1.c new file mode 100644 index 0000000..6a5aa3b --- /dev/null +++ b/string1.c @@ -0,0 +1,17 @@ + +#include +int main(){ + char string[1000]; + int x; + int freq[256] = {0}; + printf("Please type in your string. \n"); + gets(string); + for (x=0; string[x]!='\0';x++){ + freq[string[x]]++; + } + for (x=0;x<256;x++){ + if (freq[x]!=0){ + printf("%c: %d times \n", x, freq[x]); + } + } +} From d6716084206a6325959092850d8e6af0e06b2ce9 Mon Sep 17 00:00:00 2001 From: k Date: Mon, 4 Jul 2016 19:05:52 -0400 Subject: [PATCH 3/5] Hangman by Oscar So --- hangman.c | 134 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 134 insertions(+) create mode 100644 hangman.c diff --git a/hangman.c b/hangman.c new file mode 100644 index 0000000..7fefaed --- /dev/null +++ b/hangman.c @@ -0,0 +1,134 @@ +#include +#include +#include +#include +#include +#include + +void man(int x){ + switch (x){ + case 1: + printf("Number of Wrong letters: %d \n" , x); + printf(" _______ \n"); + printf(" | | \n"); + printf(" | O \n"); + printf(" | \n"); + printf(" | \n"); + printf(" | \n"); + printf("---------\n"); + break; + case 2: + printf("Number of Wrong letters: %d \n" , x); + printf(" _______ \n"); + printf(" | | \n"); + printf(" | O \n"); + printf(" | | \n"); + printf(" | | \n"); + printf(" | \n"); + printf("---------\n"); + break; + case 3: + printf("Number of Wrong letters: %d \n" ,x); + printf(" _______ \n"); + printf(" | | \n"); + printf(" | O \n"); + printf(" | | \n"); + printf(" | | \n"); + printf(" | / \\\n"); + printf("---------\n"); + break; + case 4: + printf("Number of Wrong letters: %d \n" , x); + printf("_______ \n"); + printf("| | \n"); + printf("| X \n"); + printf("| \\|/ \n"); + printf("| | \n"); + printf("| / \\\n"); + printf("--------- \n"); + break; + } +} +int main(void){ + char rsp; + do{ + srand(time(NULL)); + char WordArray[][16] = { + "hitler", + "giraffe", + "olive", + "pickle", + "programming", + "diamond", + "california", + "trash", + "phone", + "luggage" + }; + int r = rand()%10; + char *Word = WordArray[r]; + char Word2[strlen(Word)+1]; + strcpy(Word2,Word); + int WordLength = strlen(Word2); + char *DotWord = malloc(WordLength); + int t; + for (t=0;t<= WordLength; t++){ + if (t==WordLength){ + DotWord[t]='\0'; + }else{ + DotWord[t]='*'; + } + } + printf("Welcome to Hangman! \n"); + printf("To win the game, you must guess the word. \n"); + printf("You will lose after four incorrect letter guesses. \n"); + printf("All words are in lower case, please disable caps lock. \n"); + printf("Your word is: %s \n", DotWord); + printf("Please Enter Your Guess:"); + int mistakes=0; + int check=0; + int x,n=0; + char CharInput[100]; + char* CorrectWord = Word2; + while((strcmp(DotWord, CorrectWord) !=0) && (mistakes <4)){ + scanf("%c", &CharInput[n]); + if (CharInput[n] != '\n'){ + for(x=0;x Date: Tue, 5 Jul 2016 09:32:12 -0400 Subject: [PATCH 4/5] Array2? --- array2.c | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 array2.c diff --git a/array2.c b/array2.c new file mode 100644 index 0000000..ea2be19 --- /dev/null +++ b/array2.c @@ -0,0 +1,30 @@ +#include + +int main(){ + int i,j,k,n,x; + printf("How long is the array? \n"); + scanf("%d",&n); + int l[n]; + for (i=0;i Date: Tue, 5 Jul 2016 09:46:29 -0400 Subject: [PATCH 5/5] Assignment 4 by Oscar So --- assignment4.txt | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 assignment4.txt diff --git a/assignment4.txt b/assignment4.txt new file mode 100644 index 0000000..3c8ee9e --- /dev/null +++ b/assignment4.txt @@ -0,0 +1,9 @@ +1. A character array is a simple array while the string is a sequence of characters combined which can perform many different operations in the program. +2. There can be multiple data under one array so it is easy to put similar variables together. When performing and dealing with sequences and frequencies, array also benefits the programmer. The main disadvantage that I have faced in my programs is allocating a size for my arrays, because arrays have a fixed size. The bigger the array, the more memory it takes up. However, if there is too little, the program will not function. +3. Not sure, but maybe when it functions with the &operator, it does not necessarily use the first element, but instead, whichever element necessary? +4. Use strcmp to compare the two codes. eg. int strcmp(s1,s2); +if return =0l both lines are equal in length. +if return is negative, s1 is shorter and more efficient. +if return is positive, s1 is longer. + +-- Oscar So --