473,769 Members | 2,062 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

structure toupper\lower?

Chaps,
I need to properly format the case of a struct. Can I just hit it with
tolower, and then 'while (string [pos]==' ')
pos++;
string[pos]=toupper(string[pos]); to add in the higher case for the
start of each letter?
The struct will contain some integers, will tolower/upper affect any
integers?

Also...has anyone written an easy struct to xml converter yet?
Cheers for any help.

Nov 14 '05 #1
18 4803
"didgerman" <aw******@hotma il.com> writes:
I need to properly format the case of a struct.
Letters have case. Structures don't.
Can I just hit it with tolower, and then 'while (string
[pos]==' ') pos++; string[pos]=toupper(string[pos]); to add in
the higher case for the start of each letter?
You can certainly do something like that for the character
strings in the structure. Remember to cast the argument of
toupper() and tolower() to `unsigned char', though, for greatest
portability.
The struct will contain some integers, will tolower/upper
affect any integers?
You should only apply those functions to character data.
Also...has anyone written an easy struct to xml converter yet?


Maybe. A newsgroup that discusses XML tools would probably be a
better place to ask.
--
"...deficie nt support can be a virtue.
It keeps the amateurs off."
--Bjarne Stroustrup
Nov 14 '05 #2

"Ben Pfaff" <bl*@cs.stanfor d.edu> wrote in message
news:87******** ****@pfaff.stan ford.edu...
"didgerman" <aw******@hotma il.com> writes:
I need to properly format the case of a struct.


Letters have case. Structures don't.
Can I just hit it with tolower, and then 'while (string
[pos]==' ') pos++; string[pos]=toupper(string[pos]); to add in
the higher case for the start of each letter?


You can certainly do something like that for the character
strings in the structure. Remember to cast the argument of
toupper() and tolower() to `unsigned char', though, for greatest
portability.
The struct will contain some integers, will tolower/upper
affect any integers?


You should only apply those functions to character data.
Also...has anyone written an easy struct to xml converter yet?


Maybe. A newsgroup that discusses XML tools would probably be a
better place to ask.
--
"...deficie nt support can be a virtue.
It keeps the amateurs off."
--Bjarne Stroustrup


Thnx for that.
As for C to xml, I'd have thought either ng tbh.....
Nov 14 '05 #3

"didgerman" <aw******@hotma il.com> wrote in message
news:Zx******** **********@news fep4-glfd.server.ntl i.net...
Chaps,
I need to properly format the case of a struct. Can I just hit it with tolower, and then 'while (string [pos]==' ')
pos++;
string[pos]=toupper(string[pos]); to add in the higher case for the
start of each letter?
The struct will contain some integers, will tolower/upper affect any
integers?

Also...has anyone written an easy struct to xml converter yet?
Cheers for any help.


Right, getting somewhere here.
How can I use a for loop on a struct? Without using all the struct
members.....
Cheers
Nov 14 '05 #4
didgerman wrote:
.... snip ...
Right, getting somewhere here.
How can I use a for loop on a struct? Without using all the
struct members.....


There is an interesting "mental" process going on here. I don't
think it can be ascribed to a language barrier.

--
Chuck F (cb********@yah oo.com) (cb********@wor ldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net> USE worldnet address!

Nov 14 '05 #5
CBFalconer wrote:

didgerman wrote:

... snip ...

Right, getting somewhere here.
How can I use a for loop on a struct? Without using all the
struct members.....


There is an interesting "mental" process going on here. I don't
think it can be ascribed to a language barrier.


I think he's talking about using an array of offsets.
I've never used the offsetof() macro from stddef.h

--
pete
Nov 14 '05 #6
On Fri, 16 Jan 2004 09:45:06 -0000, "didgerman" <aw******@hotma il.com>
wrote:

"didgerman" <aw******@hotma il.com> wrote in message
news:Zx******* ***********@new sfep4-glfd.server.ntl i.net...
Chaps,
I need to properly format the case of a struct. Can I just hit it

with
tolower, and then 'while (string [pos]==' ')
pos++;
string[pos]=toupper(string[pos]); to add in the higher case for the
start of each letter?
The struct will contain some integers, will tolower/upper affect any
integers?
Only if there is a meaningful mapping. Otherwise, the integer remains
unchanged.
Also...has anyone written an easy struct to xml converter yet?
Cheers for any help.


Right, getting somewhere here.
How can I use a for loop on a struct? Without using all the struct
members.....
Cheers

Hmmm... I think you had better post an actual example of what you're
trying to do. I think there may be some misconceptions here, and
they're probably going to get worse without a concrete example.

--
Al Balmer
Balmer Consulting
re************* ***********@att .net
Nov 14 '05 #7

"Alan Balmer" <al******@att.n et> wrote in message
news:ki******** *************** *********@4ax.c om...
On Fri, 16 Jan 2004 09:45:06 -0000, "didgerman" <aw******@hotma il.com> wrote:

"didgerman" <aw******@hotma il.com> wrote in message
news:Zx******* ***********@new sfep4-glfd.server.ntl i.net...
Chaps,
I need to properly format the case of a struct. Can I just hit itwith
tolower, and then 'while (string [pos]==' ')
pos++;
string[pos]=toupper(string[pos]); to add in the higher case for the start of each letter?
The struct will contain some integers, will tolower/upper affect any integers?
Only if there is a meaningful mapping. Otherwise, the integer

remains unchanged.
Also...has anyone written an easy struct to xml converter yet?
Cheers for any help.


Right, getting somewhere here.
How can I use a for loop on a struct? Without using all the struct
members.....
Cheers

Hmmm... I think you had better post an actual example of what you're
trying to do. I think there may be some misconceptions here, and
they're probably going to get worse without a concrete example.

--
Al Balmer
Balmer Consulting
re************* ***********@att .net


I've gone back to strings for now.
It's Friday and I can't be arsed.
thnx anyway.
Nov 14 '05 #8

"CBFalconer " <cb********@yah oo.com> wrote in message
news:40******** *******@yahoo.c om...
didgerman wrote:

... snip ...

Right, getting somewhere here.
How can I use a for loop on a struct? Without using all the
struct members.....


There is an interesting "mental" process going on here. I don't
think it can be ascribed to a language barrier.

--
Chuck F (cb********@yah oo.com) (cb********@wor ldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net> USE worldnet address!


I'm sure that means something to you mate, well done.
Nov 14 '05 #9
"didgerman" <aw******@hotma il.com> writes:
"didgerman" <aw******@hotma il.com> wrote in message
news:Zx******** **********@news fep4-glfd.server.ntl i.net...
Chaps,
I need to properly format the case of a struct. Can I just hit it with
tolower, and then 'while (string [pos]==' ')
pos++;
string[pos]=toupper(string[pos]); to add in the higher case for the
start of each letter?
The struct will contain some integers, will tolower/upper affect any
integers?
[...]
Right, getting somewhere here.
How can I use a for loop on a struct? Without using all the struct
members.....


That's sort of like asking how you can drive a nail using a
screwdriver. You should probably just be asking how to drive a nail.

Are you trying to iterate over the members of a struct? You can't.
(Actually, you probably can if you first build an array each element
of which contains offset and size information for the struct members
you're interested in, but that's almost certainly more effort than
it's worth.)

The toupper() and tolower() functions apply to a single character:

char c = some_value;
c = toupper(c);

To map a string to upper or lower case, you can use a loop to iterate
over the characters of the array:

char *s = "hello, world";
char *ptr;
for (ptr = s; *ptr != '\0'; ptr ++) {
*ptr = toupper(*ptr);
}

or, if you're more comfortable with array indexing rather than pointer
arithmetic:

char *s = "hello, world";
int i;
for (i = 0; s[i] != '\0'; i ++) {
s[i] = toupper(s[i]);
}

You can encapsulate the loop by putting it into a function that takes
a pointer to a string and maps the string to upper case.

If you have a struct some of whose members are character arrays
containing string values, and you want to map each such member to
upper case, the best approach is just to explicitly map each member:

struct my_struct_type {
int x;
char name[MAX_NAME_LEN];
int y;
char str[SOME_OTHER_VALU E];
char c;
} my_struct_objec t;

map_string_to_u pper(my_struct_ object.name);
map_string_to_u pper(my_struct_ object.str);
my_struct_objec t.c = toupper(my_stru ct_object.c);

There are still a lot of possible complications. Are the members
you're dealing with character arrays or character pointers? If
they're arrays, are they nul-terminated strings or just arbitrary
arrays of characters; do you want to iterate over the entire array, or
just up to a terminating '\0' character?

--
Keith Thompson (The_Other_Keit h) ks***@mib.org <http://www.ghoti.net/~kst>
San Diego Supercomputer Center <*> <http://www.sdsc.edu/~kst>
Schroedinger does Shakespeare: "To be *and* not to be"
Nov 14 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
11954
by: vikas | last post by:
I have following structure in c++. typedef struct MMF_result_struct { int action; char text; int cols,rows; int month,day,year; } MMF_result; Now this structure is shared between C++ and C# using memory mapped file. We already have C++ code for handling memory mapped file. I am working on converting code for memory mapped file in C#. Now I have to pass pointer to the above structure. I converted this structure to C# as follows:
26
7095
by: Brett | last post by:
I have created a structure with five fields. I then create an array of this type of structure and place the structure into an array element. Say index one. I want to assign a value to field3 of the structure inside the array. When I try this, an error about late assignment appears. Is it possible to assign a value to a structure field that is in an array? I'm currently getting around the problem by creating a new structure, assign...
4
3897
by: marco_segurini | last post by:
Hi, From my VB program I call a C++ function that gets a structure pointer like parameter. The structure has a field that contains the structure length and other fields. My problem is that each 'double' fields get 12 bytes instead of 8 so the structure length results wrong. '----Sample
2
4845
by: Steve Turner | last post by:
I have read several interesting posts on passing structures to C dlls, but none seem to cover the following case. The structure (as seen in C) is as follows: typedef struct tag_scanparm { short cmd; short fdc; WORD dsf; short boxcar; short average; short chan_ena;
8
3325
by: Charles Law | last post by:
Can anyone suggest how I would marshal a variable length structure back from an API call. Specifically, I am looking at the WaitForDebugEvent function, which returns a DEBUG_EVENT structure. However, the DEBUG_EVENT structure is defined as a union, and the size and contents vary depending on the event code contained in the header. typedef struct _DEBUG_EVENT { DWORD dwDebugEventCode; DWORD dwProcessId;
15
8241
by: Charles Law | last post by:
I have adapted the following code from the MSDN help for PropertyInfo SetValue. In the original code, the structure MyStructure is defined as a class MyProperty, and it works as expected. There is also a minor change in class Mypropertyinfo, which I have commented out. When using a structure, however, the second call to GetValue returns "Default caption". Can anyone tell me why, and how I can make this work? <code> Imports System
3
8901
by: Kiran B. | last post by:
Hi, I am new to .net. I have two Data Structure Type ... Sturcture A and Structure B. Structure A Public Fname as String Public LastName as String Public City as String Public Zip as String End Structure
14
1805
by: Dennis | last post by:
If I have a structure like; Public Structure myStructureDef Public b() as Byte Public t as String End Structure If I pass this structure, will the values in the array b be stored on the stack or will just a pointer to the array be stored on the stack? I am trying to decide whether to use Structures or Pointers. I know that M'soft
10
4995
by: David Fort | last post by:
Hi, I'm upgrading a VB6 app to VB.net and I'm having a problem with a call to a function provided in a DLL. The function takes the address of a structure which it will fill in with values. I get an error: ---------------- An unhandled exception of type 'System.NullReferenceException' occured in
5
3796
by: =?Utf-8?B?QXlrdXQgRXJnaW4=?= | last post by:
Hi Willy, Thank you very much for your work. C++ code doesnot make any serialization. So at runtime C# code gives an serialization error at "msg_file_s sa = (msg_file_s) bf.Deserialize(ms);" I thought that it is very hard to memory map structure array. I need both read and write memory mapped file at both side of C# and C++.
0
9589
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10215
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10049
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9865
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8872
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5447
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3964
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3564
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2815
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.