1. Write a function void capitalize (char *) that is passed a string and modifie
ID: 3826275 • Letter: 1
Question
1. Write a function void capitalize (char *) that is passed a string and modifies that string to capitalize all lowercase letters in the string. I recommend you use the toupper function.
2. Write the function void censor(char *, const char *) that modifies a string (its first argument) by replacing every occurence of a patternn string (the second arguement) with all X's.
Example for #2:
String? hi mom how is it going? See you soon. // defined string
pattern? going //user input
after call to censor: hi mom how is it XXXX? See you soon. //# of X's match number of letters in pattrn string
Explanation / Answer
program:-
#include <stdio.h>
#include<ctype.h>
void capitalize(char *str){ // this method is convert lowercase to uppercase
int i=0;
while(str[i])
{
putchar (toupper(str[i])); // this is used to print after convert from lower to upper
i++;
}
}
void censor(char *first, const char *second){
}
int main()
{
char str[60];
printf("Enter string ");
scanf("%s",&str);
capitalize(str);
return 0;
}
Output:-
Enter string
hello
HELLO
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.