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
Binary file added .char_frequency.c.swp
Binary file not shown.
Binary file added array
Binary file not shown.
10 changes: 10 additions & 0 deletions assignment4.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
Ava N.
July 5, 2016

1. Character arrays are arrays of characters. For example: char c='a';. Strings are arrays of characters. For example: char[10]="Hello World";. What this will do is assign char[0]='H', char[1]='e', char[2]='l', char[3]='l', char[4]='o', char[5]=' ', char[6]='W', char[7]='o', char[8]='r', char[9]='l', char[10]='d'. String assignment is only at declaration. Also, at the beginning of the program should use "#include <string.h>".
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.

Hm, not exactly - a string is basically a character array, but with a NULL terminator as the last element.


2. The advantages of arrays in C are that it is very easy to store many integers in an array. The disadvantages of arrays in C are that the size can't change after the declaration.
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 - can you think of anything else?


3. The compiler does not implicitly generate the address of the first element of an array when an array appears as an expression.
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!


4. Two strings can be compared to see if they're equivalent in content by using strcmp(), and if the output is 0, then the strings are equal.
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.

Nice! :)

46 changes: 46 additions & 0 deletions char_frequency.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*Ava N.*/
/*Write a program that takes a string of characters and returns the frequency of each character in that string.*/
#include <stdio.h>
#include <stdlib.h>

int main(){
char input_string[98]; /*input string*/
char alpha_string[51]="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
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.

Very nicely done! You had one small warning, which caused an edge case to be missed. If the string had any capital Z's, then they weren't counted. The reason for this is because the size of the array should have been [52] instead!

int str_counter;
int alpha_counter;
int input_char;
int duplicate_count[51] = {0};

printf("Enter a character string less than 100 characters:");

scanf("%s",input_string);

/* printf("Your input string is: %s \n", input_string);
printf("input string 0 is: %c\n", input_string[0]);
printf("input_string 1 is: %c\n", input_string[1]);

*/

for (str_counter = 0; input_string[str_counter] != '\0'; str_counter++)
{

for (alpha_counter = 0; alpha_counter < 52; alpha_counter++)

{

if (input_string[str_counter] == alpha_string[alpha_counter])
duplicate_count[alpha_counter]++;
}
}

/* printf("Letter a in duplicate counter array %d\n\n",duplicate_count[0]); */


for (alpha_counter = 0; alpha_counter < 52; alpha_counter++)

{
if (duplicate_count[alpha_counter] >= 1)
printf("%c was found %d times.\n",alpha_string[alpha_counter],duplicate_count[alpha_counter]);
}
return 0;
}
Binary file added frequency
Binary file not shown.
Binary file added hangman
Binary file not shown.
55 changes: 55 additions & 0 deletions hangman.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/*Ava N.*/
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.

Not sure why you had the word print out at the end of the line

/*a program implementing the Hangman game.*/
/*I am submitting but would like to still work on this*/
#include <stdio.h>
int main(){

char word[4]="sand";
char correct[4]="----";
char input_guess;
int guessed_letters=0;
int correct_guesses;
char guesses [8];
/*incorrect_correct_guesses[0]='\0';*/
int counter;
char loop='y';
while(loop == 'y') {
printf("Guess a letter: %c \n", input_guess);
scanf("%c", &input_guess);
for(counter=0; counter<4; counter++){
if(input_guess==word[counter]){
guessed_letters++;
//guesses--;
printf("You guessed a correct letter. \n");
printf("These are the number of blank spots you have: %s \n", correct);
scanf("%s", &correct[4]);
printf("You used %d guesses of 8 guesses.\n", guessed_letters);
}
//}
else/*(input_guess!=word[counter])*/{
guessed_letters++;
printf("You guessed an incorrect letter. \n");
//guesses--;
printf("These are the number of blank spots you have: %s \n", correct);
scanf("%s", &correct[4]);
printf("You used %d guesses of 8 guesses.\n", guessed_letters);
//break;
}
}
printf("This is the word you have come up with so far: %s \n", correct);
//printf("You used %d guesses of 8 guesses. \n", guessed_letters);
if (guesses >= 8); {
printf ("You have lost. Try again next time.\n");
break;
if(word==0 /*&& blank_spots==0*/); {
printf ("You got the word, sand! You have won the game!\n");
//break;
}
printf("do you want to play again? (y/n) ");
scanf(" %c", &loop);
if(loop != 'y')
loop='n';
}
}
return 0;
}
35 changes: 35 additions & 0 deletions integer_input_array.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*Ava N.*/
/*Given an array of n integers where n > 1, return an array of same size an input array where at every index of the output array should contain the sum of all elements in the array except the element at the given index. You can have it so that the array is input by the user. */
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.

Nicely done! You did it very efficiently, so great job! The only thing is I would have included a prompt statement so the user knows to input numbers. I wasn't quite sure if you were just stuck in an infinite loop or what.

#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>

int main() {
int array_size = 5; /* Array size of 5 */
int input_array[array_size];
int output_array[array_size];
int array_sum = 0;
int counter;

for(counter = 0; counter < array_size; counter++)
{
scanf("%d", &input_array[counter]); /* input numbers into array */
}

for(counter = 0; counter < array_size; counter++)
{
array_sum +=input_array[counter]; /* calculate sum of numbers in array */
}

printf("Sum of numbers in array is: %d\n", array_sum);

for(counter=0; counter < array_size; counter++)
{
output_array[counter] = array_sum-input_array[counter];
printf("output for element %d is %d\n", counter, output_array[counter]);
}


return 0;
}
Binary file added remdup
Binary file not shown.
51 changes: 51 additions & 0 deletions remove_duplicates.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*Ava N.*/
/*Write a program that takes an array as input, removes duplicates, and outputs that array. */
//I am submitting but would like to still work on this
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

int main() {
int array_size = 5; /* Array size of 5 */
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.

Hm, not sure what's going on - did you make more progress?

int input_array[5];
int output_array[5];
int counter;
int check=0;
int duplicates=0;
int source=0;

printf("\nInsert %d numbers into the array: \n", array_size);

for(counter=0; counter<5; counter++)
{
scanf("%d", &input_array[counter]); /* input numbers into array */

printf("\n Numbers in the array: %d \n", input_array[counter]);
break;
}

for(source=0; source < array_size; source++)
{
for(check=source+1; check<array_size ;check++)
{
if(input_array[source]==input_array[check])
{
input_array[check]=input_array[source];
input_array[check]='\0';
printf("Duplicate found! %d %d \n",input_array[source],input_array[check]);
printf("source and source+1 are: %d %d \n",source,check);
printf("The number of duplicates are: %d", input_array[source]);
}
}
}
printf("\nEnd Duplicate Check\n");

for(counter = 0; counter < (array_size-duplicates+1); counter++)
{
printf("%d", input_array[counter]);
}

printf("\n\nThe End!\n\n");
return 0;
}