Capitalize first letter of a word (function)
I need to pass a word to a function and have the first letter in that word "displayed" back to the user as a capital letter, the rest lower case.
I say "displayed" because I DO NOT want to change the original.
I have the following function, which works, but I think there's a memory leak, and, this looks more complicated than what it needs to be.
I DO NOT want the CAP_WORD function to alter the original.
// This will CAP the first letter of a single word
char *CAP_WORD(char *txt)
std::string rt = "";
char *txt2 = "";
rt = txt;
txt2 = const_cast<char*>(rt.c_str());
*txt2 = (((*txt2)>='a' && (*txt2) <= 'z') ? ((*txt2)+('A'-'a')) : (*txt2));
As the function sits right now, it does not affect the original. However, I feel there's memory that's getting built that I cannot free.
I'm ready to answer any questions needed.