Solved

Function to convert null terminated string to uppercase?

Posted on 2000-03-13
7
228 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: 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!

 
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

Independent Software Vendors: 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!

Question has a verified solution.

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

Templates For Beginners Or How To Encourage The Compiler To Work For You Introduction This tutorial is targeted at the reader who is, perhaps, familiar with the basics of C++ but would prefer a little slower introduction to the more ad…
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 viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
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.

729 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