Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions Assignment4.txt
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,
Copy link
Copy Markdown
Contributor

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.


2)They can be useful for storing large amount of numbers or characters. There is no arrayIndexoutofbounds error message which can be annoying.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The 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.
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

right! if strcmp() returns 0, theyre equal!

46 changes: 46 additions & 0 deletions Dup.c
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++;
}
}
42 changes: 42 additions & 0 deletions arraySum.c
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]);
}

}

51 changes: 51 additions & 0 deletions charcounter.c
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]);
}


}

66 changes: 66 additions & 0 deletions hangman.c
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");


}