Here is a function that will modify the string you pass to it.
Code:
void StringToUpper(char * s)
{
int length = strlen(s);
for( int i=0 ; i<length ; i++)
{
s[i] = toupper( s[i] );
}
}
//use like so.
char string1[6] = "hello";
StringToUpper(string1);
If you want to save the original string, make a copy of it, and call the function on the copy
Here is a function that will create a new string that you must later free using delete
Code:
char * StringToUpper(const char * s)
{
int length = strlen(s);
char * ret = new char[length];
for( int i=0 ; i<length ; i++)
{
ret[i] = toupper(s[i]);
}
return ret;
}
//use like so
char string1[6] = "hello";
char * string2 = StringToUpper(string1);
//before the end of main do this
delete [] string2;
This version does NOT modify the original string, but you must delete the memory, before the var goes out of scope. I think this is a little messy, the first version is better.