Solved

Function to convert null terminated string to uppercase?

Posted on 2000-03-13
7
226 Views
Last Modified: 2010-04-02
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
Comment
Question by:mdanny
7 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 2612369
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
 
LVL 1

Author Comment

by:mdanny
ID: 2612437
Tried it.Get unhandled exception error...Also tried the function    _strupr from <string.h>
I'm using vc6,win32 console.
0
 
LVL 22

Accepted Solution

by:
nietod earned 20 total points
ID: 2612458
_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
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 1

Author Comment

by:mdanny
ID: 2612470
Sorry I found my mistake...
Thanks nietod
0
 
LVL 7

Expert Comment

by:KangaRoo
ID: 2612474
nietod's function looks correct. Try with

char* src = "adac";
char* dup = strdup(src);
UprStr(dup);
cout << dup << endl;
0
 
LVL 22

Expert Comment

by:nietod
ID: 2612543
>> 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
 
LVL 5

Expert Comment

by:Wyn
ID: 2613058
Great humour...
:)
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

856 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question