Question
C language ------------string A ------------- #include #include #include // Function prototype should be placed below int main(void){ char fname[20]; printf(Enter your first name: ); scanf(%s,
C language
------------string A -------------
#include
#include
#include
// Function prototype should be placed below
int main(void){
char fname[20];
printf("Enter your first name: ");
scanf("%s", &fname);
// strlen() function used to calculate the length of the string
int len = strlen(fname);
printf("There are %d letters in your first name ", len);
// TODO: print each letter in a separate line
//TODO: print all letters in a single line but put a space between each letters
printWithSpaces(fname);
return 0;
}
/* Complete the following function */
/* Use proper return type and arguments */
printWithSpaces(){
}
------------string B -------------
#include
#include
#include
// Function prototype should be placed below
int main(void){
char s[25];
int n = 10; // size of the string
// Intialize the string with '_'s
initializeBlankString( s, n);
// print the string here
return 0;
}
/* Complete the function using proper return type and arguments */
initializeBlankString( , ){
}
------------string C -------------
#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( , ){
}
------------string D -------------
#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 */
------------string E -------------
#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(){
}
Activity 1: Implementing String Manipulation Function:s Download and expand the Activity1.zip file from Canvas There should be five C program files (stringA.c, stringB.c, stringC.c, stringD.c, stringE.c) for the 1. 2. first activity 3. Your task for this activity is to implement the following four functions a. initializeBlankString(): This function should take two variables as input: an integer denoting the length of the second argument, which should be a character array. It should return nothing. The Lab Handout: Strings function should alter the passed array so that it is filled with-and is a properly terminated string b. printwithspaces(): This function will take a string as input and print the contents of the string with spaces between each character. (Hint: use the strlen() function to find the size of the passed string). The function should return nothing 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 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 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 e. checkGuess): This function should take two strings as input. If the two strings are equivalent, return a 1 from the function. If they're different, return a 0. There are at least two ways to do this: you may use the strcmp) function fromStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started