Convert char* to upper case

R

RishiD

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;
}
 
C

Christopher Benson-Manica

RishiD said:
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.
 
R

Richard Heathfield

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.]
 
R

Roberto Waltman

Christopher said:
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 ]
 
C

Christopher Layne

RishiD said:
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.
 
E

Eric Sosman

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.
 
R

Roberto Waltman

Christopher said:
Roberto said:
[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<charT> Facet
....
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 ]
 
G

Guest

Eric said:
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.
 
G

Guest

Eric said:
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.
 
G

Guest

Roberto said:
Christopher said:
Roberto said:
[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<charT> Facet
...
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 <ctype> header...?
 
C

Christopher Layne

Eric said:
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.
 
F

Fred Kleinschmidt

Christopher Layne said:
#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);
 
R

Roberto Waltman

Harald van D?k said:
Oh, provided by a ctype class, not provided by any <ctype> header...?

[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 ]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,577
Members
45,052
Latest member
LucyCarper

Latest Threads

Top