+ 2

How do you capitalize a single letter in an Array of char in C++?

How do you capitalize a single letter inside an array of char in C++? Example: char *myArray[]={“hello world”}; And capitalize only the randomly selected “h” or “o” etc? Basically how can C++ recognizes a character and know it’s capital form? Do I save the capital letter for ever small letter ex: if char letter == ‘a’ then cout “A” or ‘b’ then cout “B”....? Will this work? And is there any other way?

28th Nov 2017, 8:26 AM
Rezwan
Rezwan - avatar
2 odpowiedzi
+ 5
#include <iostream> #include <cctype> int main() { char myArray[]={"hello world"}; char letter = toupper(myArray[0]); std::cout << letter; }
28th Nov 2017, 8:40 AM
aklex
aklex - avatar
+ 8
you can check with condition: if(c >= 'a' && c <= 'z') // c is small letter if(c >= 'A' && c <= 'Z') // c is capital letter
28th Nov 2017, 8:44 AM
Vukan
Vukan - avatar