Write a function which takes a C string as an input and converts it to all upper
ID: 3631073 • Letter: W
Question
Write a function which takes a C string as an input and converts it to all uppercase characters. For each lowercase character in the C string, simply subtract 32 from it to form the uppercase character. Any non-alphabetic character in the C string should not be changed. You are not allowed to use any other functions to do this. Do not write a main function. Your function does not do any cinor cout. Hint: lowercase characters are between 'a' and 'z' where the value of 'z' equals the value of 'a' + 25. Remember, C strings are terminated with the '' character. Make sure to properly format all your code.
Explanation / Answer
string convert(string str)
{
for(int i=0; i<str.length()-1; i++)
{
if(str[i] > 96 && str[i]< 122)
{
str[i] =str[i] - 32;
}
}
return str;
}
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.