toupper
doesn't take a const character string but it only takes a single character as an integer.
Also there's a UB in your code trying to read outbound of the array:
name[20] = toupper(name[20]);
Because as you know arrays are indexed from 0 to n-1 not from 1 through n. Also even if you write it correct:
name[19] = toupper(name[19]);
The line above only converts the character 20th (index 19) to uppercase. And this is not what you wanted; you wanted to convert all the characters to uppercase.
So here is an example:
char name[20];
cout << "what is your name?" << endl;
std::cin.get(name, 20);
// name[20] = toupper(name[20]); UB
for(int i(0); i < strlen(name); i++) // use strlen instead of specifying the length at compile-time
name[i] = toupper(name[i]);
std::cout << "Your name is " << name<< std::endl;
std::cin.sync(); // only for flushing the input buffer.
std::cout << "Enter name again: \n";
std::string strName;
std::getline(std::cin, strName);
for(int i = 0; i < strName.length(); i++)
strName[i] = toupper(strName[i]);
std::cout << "name: " << strName << std::endl;
- Use class
string
it is better that to get stuck to arrays of characters, It's flexible and well designed and don't matter about size...