TL;DR:
Details
Since we're primarily English-speaking, I'll note that it appears that Mayusculas indicates capital letters, and cadena is a series or chain - in this case a C-style string.
As Presented - C-style Strings
int Mayusculas(char texto)
should be int Mayusculas(char *texto)
It needs to be a char *
since you are working with a C-style string, and not a single character. Otherwise you have nothing to iterate through.
toupper()
returns an int
, so you should cast, i.e. change
texto[liCount]=toupper(texto[liCount]);
to
texto[liCount] = (char)toupper(texto[liCount]);
- The function signature says you're returning an
int
, but you don't actually return anything. So either change it to return void, or return something. (liCount
, maybe?)
Alternative: std::string
But you tagged this question as C++, so why not use std::string
instead of C-style strings? They're safer, and easier to work with.
Quoting Pierre from Convert a String In C++ To Upper Case:
#include <algorithm>
#include <string>
std::string str = "Hello World";
std::transform(str.begin(), str.end(),str.begin(), ::toupper);
Or if you still want it in your own function,
#include <algorithm>
#include <string>
#include <iostream>
using namespace std;
string Mayusculas(std::string str)
{
transform(str.begin(), str.end(), str.begin(), ::toupper);
return str;
}
int main()
{
string Cadena = "Hola al Mundo";
cout << Mayusculas(Cadena) << endl;
return 0;
}
That way returns the result as a string. But if you want to modify it in place like your original, you can do this instead. See it work at Ideone.
void Mayusculas(std::string & str) // reference parameter
{
transform(str.begin(), str.end(), str.begin(), ::toupper);
}
int main()
{
string Cadena = "Hola al Mundo";
Mayusculas(Cadena);
cout << Cadena << endl;
return 0;
}