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
18 4804
didgerman wrote: "CBFalconer " <cb********@yah oo.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********@yah oo.com) (cb********@wor ldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net> USE worldnet address!
"CBFalconer " <cb********@yah oo.com> wrote in message
news:40******** *******@yahoo.c om... didgerman wrote: "CBFalconer " <cb********@yah oo.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********@yah oo.com) (cb********@wor ldnet.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.
"Keith Thompson" <ks***@mib.or g> wrote in message
news:ln******** ****@nuthaus.mi b.org... "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"
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....... .
"didgerman" <aw******@hotma il.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[]="ABCDEFGHIJKLM NOPQRSTUVWXYZab cdefghijklmnopq rstuvwxyz.\
\n",*q="kl BIcNBFr.NKEzjwC IxNJC";int i=sizeof p/2;char *strchr();int putchar(\
);while(*q){i+= strchr(p,*q++)-p;if(i>=(int)si zeof p)i-=sizeof p-1;putchar(p[i]\
);}return 0;}
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_FAILU RE);
}
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(astri ngs[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********@yah oo.com) (cb********@wor ldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home .att.net> USE worldnet address!
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((unsign ed char) c);
--
Hallvard
On Fri, 16 Jan 2004 15:05:09 GMT, pete <pf*****@mindsp ring.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
Hallvard B Furuseth <h.b.furuseth(n ospam)@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((unsign ed char) c);
Oops, you're right. Thanks.
--
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"
"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.
Chaps, I'm done, just about.
Thnx for all the help.
I'll continue to lurk here and pick a few things up.
Cheers. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
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:
|
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...
|
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
|
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;
|
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;
| |
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
|
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
|
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
|
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
|
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++.
|
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...
| |
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
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...
|
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...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
| |
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
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...
| |