-
Notifications
You must be signed in to change notification settings - Fork 16
Assignment4 #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Assignment4 #18
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. right - the fact that the size can't be changed is a disadvantage. |
||
|
|
||
| 3)No idea. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you should always attempt questions! but the short answer is that a compiler doesn't generate the address whenever it appears in an expression. |
||
|
|
||
| 4) You could used the strcmp method or you could look at each index and compare those one by one. | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. right! if strcmp() returns 0, theyre equal! |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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<stdio.h> | ||
|
|
||
| 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<aryS;i++){ | ||
| scanf("%d",&ary[i]); | ||
| } | ||
|
|
||
|
|
||
| for(i=0;i<aryS;i++){ | ||
| for(j=i+1;j<aryS;j++){ | ||
| if(ary[i]!=ary[j]){ | ||
| tracker++; | ||
| } | ||
| } | ||
| } | ||
| int ary2[tracker]; | ||
|
|
||
| for(i=0;i<aryS;i++){ | ||
| for(j=i+1;j<aryS;j++){ | ||
| if(ary[i]==ary[j]) | ||
| break; | ||
| ary2[i]=ary[i+1]; | ||
| i--; | ||
| break; | ||
| } | ||
| } | ||
|
|
||
|
|
||
| printf("\n"); | ||
| for(i=0;i<tracker;){ | ||
| printf("%d\n",ary2[i]); | ||
| i++; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,42 @@ | ||
| //Clarke Littlejohn | ||
| //Arraysum of previous elements | ||
| //i am not sure if this correct code | ||
|
|
||
| #include<stdio.h> | ||
|
|
||
|
|
||
| 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<arraySize){ | ||
| scanf("%d",&array1[i]); | ||
| i++; | ||
| } | ||
|
|
||
|
|
||
| for(i=0;i<arraySize;i++){ | ||
| sum=0; | ||
| for(j=0;j<arraySize;j++){ | ||
| if(i!=j){ | ||
| sum+=array1[j]; | ||
| } | ||
| } | ||
| array2[i]=sum; | ||
| } | ||
|
|
||
|
|
||
| for(i=0;i<arraySize;i++){ | ||
| printf("%d\t",array2[i]); | ||
| } | ||
|
|
||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| //Clarke Littlejohn | ||
| // When entering a clk it works a intended but when entering asd it doesnt seem it work i cant figure out why. | ||
|
|
||
|
|
||
| #include<stdio.h> | ||
|
|
||
|
|
||
| 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]); | ||
| } | ||
|
|
||
|
|
||
| } | ||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| //Clarke Littlejohn | ||
| //Hangman game | ||
| // Sometimes the game doesn't work when it is started do not know why. | ||
|
|
||
| #include<stdio.h> | ||
| #include<string.h> | ||
|
|
||
| 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"); | ||
|
|
||
|
|
||
| } | ||
|
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right - the only real difference is that a string's character array must point to a NULL terminator.