Question: C language Your task for this activity is to implement the following functions: d. revealGuessedLetter(): This function will take two strings and a character as

C language

Your task for this activity is to implement the following functions:

d. revealGuessedLetter(): This function will take two strings and a character as input. The function should alter the second string in the following way: For every position in the first string that contains the character passed in as the third argument to the function, change the same position in the second string to that character. For example:

String1 = dinosaur

String2 = _ _ _ _ _ _ _ _ The character passed is a. The function should alter String2 so that it becomes

_ _ _ _ _ a _ _. Note: ignore the spaces in the example and assume that each element in the array is an underscore. You may assume that the strings are of equal length. The function should return a 1 if any letters were changed in string2, and a 0 otherwise.

Given:

#include #include #include

// Function prototype should be placed below

int main(void){ char fname[20]; printf("Enter your first name again: "); scanf("%s", fname); int len = strlen(fname); // length of first name // declare another string of same length (dynamic declaration) char *str = (char *) malloc(sizeof(char) * len + 1); // initialize the string with '_'s initializeBlankString(str, len); char c; printf("Enter a letter: "); getchar(); scanf("%c", &c);

// check if the letter is present in your first name int check = checkLetter(fname, c);

// If present, put that letter in the exact same position in the 2nd string (filled with '_'s) int flag = revealGuessedLetter(c, str, fname); // Output if the second string has been updated and print both the strings

return 0; }

/* Complete the functions */

revealGuessedLetter( , , ){

}

/* Copy and paste the functions you wrote in previous three programs */

e. checkGuess(): This function should take two strings as input. If the two strings are equivalent, return a 1 from the function. If theyre different, return a 0. There are at least two ways to do this: you may use the strcmp() function from , or you can iterate over every character in the strings. You may assume that the strings are equal length.

Given:

#include #include

// Function prototype should be placed below

int main(void){ //TODO: compare two strings char s1[10]; char s2[10]; printf("Enter the first string: "); scanf("%s", &s1); printf("Enter the second string: "); scanf("%s", &s2); int c = checkGuess(s1, s2); // output if they are matched or not

return 0; }

/* Complete the function */

checkGuess(){

}

c. checkLetter() : The function will take a character and string as input. It checks if the letter is present inside the string. If Yes, it returns 1, else it returns 0.

Given:

#include #include #include

// Function prototype should be placed below

int main(void){ char fname[20]; printf("Enter your first name: "); scanf("%s", fname); //check if a letter present in your firstname char letter; printf("Enter a letter: "); getchar(); scanf("%c", &letter); int check = checkLetter(fname, letter); //TODO: output if the letter present or not return 0; }

/* Complete the function */

checkLetter( , ){

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!