+ 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?
2 Answers
+ 5
#include <iostream>
#include <cctype>
int main()
{
char myArray[]={"hello world"};
char letter = toupper(myArray[0]);
std::cout << letter;
}
+ 8
you can check with condition:
if(c >= 'a' && c <= 'z')
// c is small letter
if(c >= 'A' && c <= 'Z')
// c is capital letter