• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 236
  • Last Modified:

Function to convert null terminated string to uppercase?

I'm new to C++ so the q might seem easy.
With which function I convert null terminated string to uppercase?
char *s="adac";
somefunc(s);
now *s is "ADAC"
0
mdanny
Asked:
mdanny
1 Solution
 
nietodCommented:
You can use toupper() to convert a single character to uppercase.  

You can write code to convert an entire string like

void UprStr(char *str)
{
   while (*str)
   {
        *str = toupper(*str);
        ++str;
    }
}
0
 
mdannyAuthor Commented:
Tried it.Get unhandled exception error...Also tried the function    _strupr from <string.h>
I'm using vc6,win32 console.
0
 
nietodCommented:
_strupt is fine.  But it is not a standard function.  It is one that Microsoft provides with their compiler, but it might not be found on onther compilers.  The fucntion I wrote is portable, so it can be used on ANY compiler.

>> Get unhandled exception error
There is no problem with the function I provided.  The problem must be elsewhere in the program or in the way you are using the function.

It is not necessary to reject an answer if you simply want clarificationor additional help.  You ca simply post a comment askign for more help.
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
mdannyAuthor Commented:
Sorry I found my mistake...
Thanks nietod
0
 
KangaRooCommented:
nietod's function looks correct. Try with

char* src = "adac";
char* dup = strdup(src);
UprStr(dup);
cout << dup << endl;
0
 
nietodCommented:
>> nietod's function looks correct.
But its always hard to be sure with a function of that sort of complexity.  There may be a bug lurking somewhere.  :-)
0
 
WynCommented:
Great humour...
:)
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now