Question: C language Your task for this activity is to implement the following four functions: a. initializeBlankString(): This function should take two variables as input: an
C language
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 function should alter the passed array so that it is filled with _ and is a properly terminated string.
Given:
#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( , ){
}
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.
Given:
#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(){
}
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.
#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
Get step-by-step solutions from verified subject matter experts
