473,385 Members | 1,693 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 4777
"didgerman" <aw******@hotmail.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.
--
"...deficient support can be a virtue.
It keeps the amateurs off."
--Bjarne Stroustrup
Nov 14 '05 #2

"Ben Pfaff" <bl*@cs.stanford.edu> wrote in message
news:87************@pfaff.stanford.edu...
"didgerman" <aw******@hotmail.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.
--
"...deficient 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******@hotmail.com> wrote in message
news:Zx******************@newsfep4-glfd.server.ntli.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********@yahoo.com) (cb********@worldnet.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******@hotmail.com>
wrote:

"didgerman" <aw******@hotmail.com> wrote in message
news:Zx******************@newsfep4-glfd.server.ntli.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.net> wrote in message
news:ki********************************@4ax.com...
On Fri, 16 Jan 2004 09:45:06 -0000, "didgerman" <aw******@hotmail.com> wrote:

"didgerman" <aw******@hotmail.com> wrote in message
news:Zx******************@newsfep4-glfd.server.ntli.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********@yahoo.com> wrote in message
news:40***************@yahoo.com...
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********@yahoo.com) (cb********@worldnet.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******@hotmail.com> writes:
"didgerman" <aw******@hotmail.com> wrote in message
news:Zx******************@newsfep4-glfd.server.ntli.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_VALUE];
char c;
} my_struct_object;

map_string_to_upper(my_struct_object.name);
map_string_to_upper(my_struct_object.str);
my_struct_object.c = toupper(my_struct_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_Keith) 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
didgerman wrote:
"CBFalconer" <cb********@yahoo.com> wrote in message
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'm sure that means something to you mate, well done.


Your questions and statements make absolutely no sense in the
context of C programming. You seem to have some very peculiar
ideas about it. For example, a for loop is a control mechanism.
It is not something that is applied to something else.

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Nov 14 '05 #11

"CBFalconer" <cb********@yahoo.com> wrote in message
news:40***************@yahoo.com...
didgerman wrote:
"CBFalconer" <cb********@yahoo.com> wrote in message
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'm sure that means something to you mate, well done.


Your questions and statements make absolutely no sense in the
context of C programming. You seem to have some very peculiar
ideas about it. For example, a for loop is a control mechanism.
It is not something that is applied to something else.

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


What I want to do is loop through a struct without specifying all the
members.
A for loop would suit me best.
Nov 14 '05 #12

"Keith Thompson" <ks***@mib.org> wrote in message
news:ln************@nuthaus.mib.org...
"didgerman" <aw******@hotmail.com> writes:
"didgerman" <aw******@hotmail.com> wrote in message
news:Zx******************@newsfep4-glfd.server.ntli.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_VALUE];
char c;
} my_struct_object;

map_string_to_upper(my_struct_object.name);
map_string_to_upper(my_struct_object.str);
my_struct_object.c = toupper(my_struct_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_Keith) 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"


Thnx mate, got it in one there.
I've got char' arrays, nul terminated iterating over the 'isalpha'
chars only would be best, in case the code develops further.
Unlikely........
Nov 14 '05 #13
"didgerman" <aw******@hotmail.com> writes:
What I want to do is loop through a struct without specifying all the
members.
A for loop would suit me best.


This isn't something that can be done in a natural way in C.
Maybe you should describe your actual situation in more detail,
and then perhaps we can give you a better way to cast that into C
terms.
--
int main(void){char p[]="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuv wxyz.\
\n",*q="kl BIcNBFr.NKEzjwCIxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+=strchr(p,*q++)-p;if(i>=(int)sizeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}
Nov 14 '05 #14
didgerman wrote:
.... snip ...
I've got char' arrays, nul terminated iterating over the 'isalpha'
chars only would be best, in case the code develops further.


Then you are probably using the wrong data structure. Consider
something like:

/* if at file level this will be auto-initialized to NULLs */
char *astrings[MAXCOUNT];

void insert(int where, const char *s)
{
if (astrings[where] = malloc(1 + strlen(s)))
strcpy(astrings[where], s);
else
exit(EXIT_FAILURE);
}

which you can use to install modifiable strings into the astrings
array. You might have something like:

insert(0, "string 0");
insert(1, "string 1");

and so forth. Now, you can scan through them all with:

for (i = 0; i < MAXCOUNT; i++)
operateon(astrings[i]);
}

and operateon should guard against NULL and look something like:

void operateon(char *s)
{
if (s) {
/* whatever code you need, s is non-NULL */
}
}

All this assumes we have understood what you are trying to do,
which you did not describe very well. Don't forget the
appropriate #includes, which I have not specified above. If I am
right about your needs, ensure you understand why I wrote each and
every code line above.

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!
Nov 14 '05 #15
Keith Thompson wrote:
char c = some_value;
c = toupper(c);


That can crash if 'char' is signed c becomes negative (i.e. for
non-ASCII characters if you have 8-bit bytes and an ASCII superset).
It should be

c = toupper((unsigned char) c);

--
Hallvard
Nov 14 '05 #16
On Fri, 16 Jan 2004 15:05:09 GMT, pete <pf*****@mindspring.com> wrote:
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


I've found offsetof() useful for building portable, efficient,
table-driven, readable and easy-to-maintain access to binary files (of
external definition). I define tables that map "natural" C structures
to the underlying, unaligned binary data, and handle endianness (sic?)
implicitly.

Thus, C-aligned, native-endian structures can be read and written from
any-endian binary files with simple calls.

The OP could do something similar to point to the strings in the
structs, but unless he's got dozens of structs to do this with, it's
probably not worth the effort.

- Sev

Nov 14 '05 #17
Hallvard B Furuseth <h.b.furuseth(nospam)@usit.uio(nospam).no> writes:
Keith Thompson wrote:
char c = some_value;
c = toupper(c);


That can crash if 'char' is signed c becomes negative (i.e. for
non-ASCII characters if you have 8-bit bytes and an ASCII superset).
It should be

c = toupper((unsigned char) c);


Oops, you're right. Thanks.

--
Keith Thompson (The_Other_Keith) 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 #18

"didgerman" <aw******@hotmail.com> wrote in message
news:Zx******************@newsfep4-glfd.server.ntli.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.


Chaps, I'm done, just about.
Thnx for all the help.
I'll continue to lurk here and pick a few things up.
Cheers.
Nov 14 '05 #19

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

Similar topics

2
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#...
26
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...
4
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...
2
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...
8
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. ...
15
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...
3
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...
14
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...
10
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...
5
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);"...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.