469,924 Members | 1,529 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,924 developers. It's quick & easy.

Convert char* to upper case

Hi,

For some reason I am blanking this Friday morning. I have a class
constructor call Point as shown below. Trying to figure out how I can
make the arguments passed in all upper case before I set the member
variables.

Thanks for the insight.

RishiD

Point(const char* name,
const char* description,
const char* iomid,
const char* address,
const char* type,
Event* event)
{
m_strName = name;
m_strDesc = description;
m_strAddress = address;
m_strType = type;
m_strParentName = iomid;
m_Event = event;
}

Feb 16 '07 #1
13 23324
RishiD <ri****@gmail.comwrote:
For some reason I am blanking this Friday morning.
Starting with posting code that seems a little like C++ to
comp.lang.c? (It has indeed been a lengthy week.)
I have a class
constructor call Point as shown below. Trying to figure out how I can
make the arguments passed in all upper case before I set the member
variables.
There's no builtin C function to do this, but you could write one
using the builtin toupper() for characters. Alternatively, there
might be a C++ way to do this, if you are indeed writing C++ as it
seems.

--
C. Benson Manica | I *should* know what I'm talking about - if I
cbmanica(at)gmail.com | don't, I need to know. Flames welcome.
Feb 16 '07 #2
RishiD said:
Hi,

For some reason I am blanking this Friday morning. I have a class
constructor call Point as shown below.
....which makes me think you're using C++, so I've cross-posted this
reply to comp.lang.c++, and set followups to that group.
Trying to figure out how I can
make the arguments passed in all upper case before I set the member
variables.
In C, you'd probably write a function that calls toupper() in a loop -
but in C++ there may be a more C++y way to do it.

[Remainder of your article retained, for clc++'s convenience. Hi guys,
long time no see.]
>
Thanks for the insight.

RishiD

Point(const char* name,
const char* description,
const char* iomid,
const char* address,
const char* type,
Event* event)
{
m_strName = name;
m_strDesc = description;
m_strAddress = address;
m_strType = type;
m_strParentName = iomid;
m_Event = event;
}
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at the above domain, - www.
Feb 16 '07 #3
Christopher Benson-Manica wrote:
>RishiD <ri****@gmail.comwrote:
>>... Trying to figure out how I can
make the arguments passed in all upper case before I set the member
variables.

There's no builtin C function to do this, but you could write one
using the builtin toupper() for characters. Alternatively, there
might be a C++ way to do this, if you are indeed writing C++ as it
seems.
[OT] That would be, surprisingly, the toupper(c) or toupper(begin,end)
services provided in <ctype>

Roberto Waltman

[ Please reply to the group,
return address is invalid ]
Feb 16 '07 #4
RishiD wrote:
Hi,

For some reason I am blanking this Friday morning. I have a class
constructor call Point as shown below. Trying to figure out how I can
make the arguments passed in all upper case before I set the member
variables.

Point(const char* name,
const char* description,
const char* iomid,
const char* address,
const char* type,
Event* event)
{
m_strName = name;
m_strDesc = description;
m_strAddress = address;
m_strType = type;
m_strParentName = iomid;
m_Event = event;
}
#include <ctype.h>

void up(char *q)
{
unsigned char c;

while (*q) { c = *q; *q = toupper(c); q++; }

return;
}

Also your function specifies "const char *". You might want to adhere to that.
Feb 16 '07 #5
Roberto Waltman wrote:
[OT] That would be, surprisingly, the toupper(c) or toupper(begin,end)
^^^^^^^^^^^^^^^^^^

???
Feb 16 '07 #6
Christopher Layne wrote On 02/16/07 11:07,:
Roberto Waltman wrote:

>>[OT] That would be, surprisingly, the toupper(c) or toupper(begin,end)

^^^^^^^^^^^^^^^^^^

???
Go back and read Roberto's message again, this time
paying attention to the text he quoted and responded to.

--
Er*********@sun.com
Feb 16 '07 #7
Christopher Layne wrote:
>Roberto Waltman wrote:
>[OT] That would be, surprisingly, the toupper(c) or toupper(begin,end)
^^^^^^^^^^^^^^^^^^
Off-topic, wearing a C++ hat:
From Josuttis "The C++ Standard Library", 1st ed, 10th printing, page
716.

The facet ctype is a template class parameterized with a character
type...
....
Table 14.16. Services defined by the ctype<charTFacet
....
ct.toupper(beg,end) Converts each letter in the range between beg and
end by replacing the letter with the result of toupper()

Roberto Waltman

[ Please reply to the group,
return address is invalid ]
Feb 16 '07 #8
Eric Sosman wrote:
Christopher Layne wrote On 02/16/07 11:07,:
Roberto Waltman wrote:

>[OT] That would be, surprisingly, the toupper(c) or toupper(begin,end)
^^^^^^^^^^^^^^^^^^

???

Go back and read Roberto's message again, this time
paying attention to the text he quoted and responded to.
The C++ part? toupper(begin,end) is new to me if it's valid at all,
regardless of which language is used.

Feb 16 '07 #9
Eric Sosman wrote:
Christopher Layne wrote On 02/16/07 11:07,:
Roberto Waltman wrote:

>[OT] That would be, surprisingly, the toupper(c) or toupper(begin,end)
^^^^^^^^^^^^^^^^^^

???

Go back and read Roberto's message again, this time
paying attention to the text he quoted and responded to.
The C++ part? toupper(begin,end) is new to me if it's valid at all,
regardless of which language is used.

Feb 16 '07 #10
Roberto Waltman wrote:
Christopher Layne wrote:
Roberto Waltman wrote:
[OT] That would be, surprisingly, the toupper(c) or toupper(begin,end)
^^^^^^^^^^^^^^^^^^
[un-snip]
services provided in <ctype>

Off-topic, wearing a C++ hat:
From Josuttis "The C++ Standard Library", 1st ed, 10th printing, page
716.

The facet ctype is a template class parameterized with a character
type...
...
Table 14.16. Services defined by the ctype<charTFacet
...
ct.toupper(beg,end) Converts each letter in the range between beg and
end by replacing the letter with the result of toupper()
Oh, provided by a ctype class, not provided by any <ctypeheader...?

Feb 16 '07 #11
Eric Sosman wrote:
Go back and read Roberto's message again, this time
paying attention to the text he quoted and responded to.
You are correct. I thought he was responding in general, not specifically to
the C++ part. Part of that may be due to the fact that I don't generally
think in any C++ mode while i'm in this NG.
Feb 16 '07 #12
"Harald van D?k" wrote:
>Roberto Waltman wrote:
>... C++ stuff ...
ct.toupper(beg,end) Converts each letter in the range between beg and
end by replacing the letter with the result of toupper()

Oh, provided by a ctype class, not provided by any <ctypeheader...?
[Still-off-topic] Beginning to get beyond my depth, (no books at hand
now.) I believe it is provided by the standard headers, but somehow
linked to (buried under?) the locale selection mechanisms.

There is also a toupper(c, loc) that will convert c to upper case IFF
it is a lower case character in locale loc.

Roberto Waltman

[ Please reply to the group,
return address is invalid ]
Feb 16 '07 #13

"Christopher Layne" <cl****@com.anodizedwrote in message
news:11************@news-west.n...
RishiD wrote:
>Hi,

For some reason I am blanking this Friday morning. I have a class
constructor call Point as shown below. Trying to figure out how I can
make the arguments passed in all upper case before I set the member
variables.

Point(const char* name,
const char* description,
const char* iomid,
const char* address,
const char* type,
Event* event)
{
m_strName = name;
m_strDesc = description;
m_strAddress = address;
m_strType = type;
m_strParentName = iomid;
m_Event = event;
}

#include <ctype.h>

void up(char *q)
{
unsigned char c;

while (*q) { c = *q; *q = toupper(c); q++; }

return;
}

Also your function specifies "const char *". You might want to adhere to
that.
Especially since this can cause bad things to happen using the above code:
char *ptr = "test";
up(ptr);
--
Fred L. Kleinschmidt
Boeing Associate Technical Fellow
Technical Architect, Software Reuse Project
Feb 16 '07 #14

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by programmerforhire | last post: by
17 posts views Thread by Janice | last post: by
6 posts views Thread by Manish | last post: by
5 posts views Thread by Mariame | last post: by
19 posts views Thread by Eric Lindsay | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.