From f31446b20fa6966d79e9885832e47e05215e382e Mon Sep 17 00:00:00 2001 From: Clarke Littlejohn Date: Tue, 5 Jul 2016 10:01:01 -0400 Subject: [PATCH] Assignment4 --- Assignment4.txt | 9 +++++++ Dup.c | 46 ++++++++++++++++++++++++++++++++++ arraySum.c | 42 +++++++++++++++++++++++++++++++ charcounter.c | 51 ++++++++++++++++++++++++++++++++++++++ hangman.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 214 insertions(+) create mode 100644 Assignment4.txt create mode 100644 Dup.c create mode 100644 arraySum.c create mode 100644 charcounter.c create mode 100644 hangman.c diff --git a/Assignment4.txt b/Assignment4.txt new file mode 100644 index 0000000..e26934b --- /dev/null +++ b/Assignment4.txt @@ -0,0 +1,9 @@ +Clarke Littlejohn + +1) From what i understand there is not really a difference between the two but from readng online string points to a terminator, + +2)They can be useful for storing large amount of numbers or characters. There is no arrayIndexoutofbounds error message which can be annoying. + +3)No idea. + +4) You could used the strcmp method or you could look at each index and compare those one by one. diff --git a/Dup.c b/Dup.c new file mode 100644 index 0000000..a02ec04 --- /dev/null +++ b/Dup.c @@ -0,0 +1,46 @@ +//Clarke Littlejohn +//removes duplicates +//Couldn't get this one to work. I tried multiple differents ways and sometimes it would work someimtes it wouldn't. +#include + +int main(){ + int i=0; + int j=0; + int aryS; + int tracker=0; + + printf("Enter the size of the array\n"); + scanf("%d",&aryS); + int ary[aryS]; + printf("Now enter in a set of numbers and it will remove dupclicates from it.\n"); + for(;i + + +int main(){ + + int arraySize; + printf("This program will give you the sum of the the prevouis elements in the array.\nEnter number to set the size of the Array."); + scanf("%d",&arraySize); + int array1 [arraySize]; + int array2 [arraySize]; + int i=0; + int j,sum; + printf("Now enter the values you want to be summed.\n"); + + + while(i + + +int main(){ + + char str[100]; + char alphabet[52]; + int i,counter2; + int charC [52]; + char userIn; + for(i=0;i<53;i++){ + charC[i]=0; + } + //fills the alphabet array + for(i=65;i<(65+26);i++){ + alphabet[i-65]=i; + } + for(i=97;i<(97+26);i++){ + alphabet[i-71]=i; + } + + printf("Enter in a string.\n"); + fgets(str,sizeof(str),stdin); + //suppose to increase the char Counter + for(i=0;i<26;i++){ + + for(counter2=25;counter2<51;counter2++){ + if(alphabet[counter2]==str[i]) + charC[counter2]++; + } + for(counter2=0;counter2<27;counter2++){ + if(alphabet[counter2]==str[i]) + charC[counter2]++; + } + } + + for(i=0;i<26;i++){ + if(charC[i]!=0) + printf("%c = %d\n",alphabet[i],charC[i]); + + if(charC[i+26]!=0) + printf("%c = %d\n",alphabet[i+26],charC[i+26]); + } + + +} + diff --git a/hangman.c b/hangman.c new file mode 100644 index 0000000..46d7ca8 --- /dev/null +++ b/hangman.c @@ -0,0 +1,66 @@ +//Clarke Littlejohn +//Hangman game +// Sometimes the game doesn't work when it is started do not know why. + +#include +#include + +int main(){ + + char word [16] ="computerscience"; + char wrong [16]; + int wrongT=0; + char board [16]="_______________"; + int boolean =0; + int counter=0; + printf("Let's play hangman. You guess the word. If you guess incorrectly five times you lose.\n"); + + char userIn; + int i; + + while(i<=4){ + if(userIn!='\n') + printf("Guess a Letter:"); + + if(strcmp(word,board)==0) + break; + scanf("%c",&userIn); + int j=0; + boolean=0; + for(;j<16;j++){ + if(word[j]==userIn){ + boolean=1; + board[j]=word[j]; + counter++; + } + } + if(boolean==0&&userIn!='\n'){ + wrong[wrongT]=userIn; + wrongT++; + i++; + } + int k=0; + printf("\n Wrong Guesses\n "); + + for(;k<16;k++){ + if(k%6==0&&k!=0) + printf("\n"); + printf("%c",wrong[k]); + } + if(i==5) + break; + + printf("\n"); + for(k=0;k<16;k++){ + printf("%c",board[k]); + } + printf("\n"); + } + if(strcmp(word,board)==0) + printf("You won!\n"); + else if(i==4) + printf("You lost.\n"); + + + } +