Please complete the C code. The code that needs completing is outlined in the co
ID: 3781978 • Letter: P
Question
Please complete the C code. The code that needs completing is outlined in the comments.
#include <stdio.h>
#include <stdlib.h>
/*converts ch to upper case, assuming it is in lower case currently*/
char toUpperCase(char ch){
return ch-'a'+'A';
}
/*converts ch to lower case, assuming it is in upper case currently*/
char toLowerCase(char ch){
return ch-'A'+'a';
}
void sticky(char* word){
/*Convert to sticky caps*/
}
int main(){
/*Read word from the keyboard using scanf*/
/*Call sticky*/
/*Print the new word*/
return 0;
}
Explanation / Answer
Below is the completed code:
#include <stdio.h>
#include <stdlib.h>
/*converts ch to upper case, assuming it is in lower case currently*/
char toUpperCase(char ch){
return ch-'a'+'A';
}
/*converts ch to lower case, assuming it is in upper case currently*/
char toLowerCase(char ch){
return ch-'A'+'a';
}
voidsticky(char*word){
bool upperCase = true;
while(*word != ''){
if(upperCase){
*word = toupper(*word);
}else {
*word = tolower(*word);
}
upperCase = !upperCase;
word++;
}
}
int main(){
char word[20];
printf("Please enter a word to sticky-fy! ");
scanf("%19s", word);
sticky(word);
/*Print the new word*/
printf("%s ", word);
return 0;
}
Thank you.
voidsticky(char*word){
bool upperCase = true;
while(*word != ''){
if(upperCase){
*word = toupper(*word);
}else {
*word = tolower(*word);
}
upperCase = !upperCase;
word++;
}
}
int main(){
char word[20];
printf("Please enter a word to sticky-fy! ");
scanf("%19s", word);
sticky(word);
/*Print the new word*/
printf("%s ", word);
return 0;
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.