Solved

Function to convert null terminated string to uppercase?

Posted on 2000-03-13
7
221 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
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 learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

863 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

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now