hi!
is it possible to access the members of a struct (e.g. 10 members) in a
loop, comparable to an array?
tia,
E 4 10809
>is it possible to access the members of a struct (e.g. 10 members) in a loop, comparable to an array?
If you're expecting to iterate over the members of unknown name and
type, NO. You can make a table of the member names, types, and
offset (using offsetof()), and use that, but you have to keep it
up to date with the real struct, and it's messy.
If you need this, you probably want an array as a struct member.
Gordon L. Burditt
Erich Pul wrote: hi!
is it possible to access the members of a struct (e.g. 10 members) in a loop, comparable to an array?
No (unless those 10 members happen to be an array!), C has nothing like
the foraech construct found in some other languages.
--
Ian Collins. No (unless those 10 members happen to be an array!), C has nothing like the foraech construct found in some other languages.
thank you - i will pack the values in an array and have my loop go
through it
E
On 23 Jun 2006 00:12:02 -0700, "Erich Pul" <er*******@blac kbox.net>
wrote:
hi!
is it possible to access the members of a struct (e.g. 10 members) in a
loop, comparable to an array?
As others have said, no. There are two things you can do that may, or
may not, approach this closely enough for your purpose:
enum { height /* = 0 */, width /* = 1 */, depth /* etc. */, NUMDIM };
struct dims { double dim [NUMDIM /* or 3 */]; } foo;
.... volume = foo.dim[height] * foo.dim[width] * foo.dim[depth]; ...
/* best not to use simple names like height because a macro
takes the identifier 'out of play' for ALL other use */
#define d_height dim[0]
#define d_width dim[1]
#define d_depth dim[2]
#define d_NUMDIM 3
struct dims { double dim [NUMDIM]; } foo;
.... volume = foo.d_height * foo.d_width * foo.d_depth; ...
- David.Thompson1 at worldnet.att.ne t This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Random Person |
last post by:
Does anyone know how to use VBA to relink tables between two MS Access
databases? We have two databases, one with VBA code and the other with
data tables. The tables are referenced by linked tables in the database
where the code resides. If we move the database with the data tables to
a new directory, the links are no longer valid.
I tried to update the links by changing the Connect property and refreshing:
Set td = db.TableDefs(0)...
|
by: jimjim |
last post by:
Hello,
Any help will be much appreciatted. My problem is as follows:
I declare as global variables:
typedef struct _Node{ ..; ..;}Node;
Node *Graph;
in a function called initiallise(), I allocate memory and copy information:
for(i )
|
by: Michael B Allen |
last post by:
Consider the following structure with a union:
struct shape {
int type;
union {
struct circle c;
struct square s;
struct polydoodle p;
} u;
};
|
by: sherifffruitfly |
last post by:
Hi,
I'm just learning cpp, and the exercise I'm working on is basically as
follows:
1) Create a struct type with 4 members (char, char, char, int).
2) Create an array of, say 3 instances of the struct, and populate them
with data.
3) cin 1, 2, 3, or 4 from the user
4) If the user selected, say, 2, display the contents of the 2nd data
|
by: edson |
last post by:
Greetings
For certain operations I would like to have easy access to struct
members. Here is an example.
struct mystruct {
char member1;
char member1;
char member1;
};
| |
by: A n g l e r |
last post by:
Hello everybody.
I've got such an aching me question concerning fast & well optimized
access to members of a structure (or class) and ways that VC compiler
handles it. Let's imagine the following structure and an array of its
type:
struct SSth1
{
int nMbr1, nMbr2, nMbr3;
|
by: noone |
last post by:
What is the syntax to access members of a structure without
explicitly naming the structure in every access?
struct mytype {
int a;
char* b;
long c;
} IT;
How can I access the structure members in a way similar to the old pascal
|
by: Mahendra Kumar Kutare |
last post by:
I am trying to implement a webserver with boss-worker model thread
pool implementation -
I have a header declaration threadpool.h as -
typedef struct threadpool_work {
void (*routine) ();
void *arg;
struct threadpool_work *next;
} threadpool_work_t;
|
by: jbholman |
last post by:
I am pretty new to C and doing my first project in C. I actually read
almost the entire FAQ, but can't seem to figure out this problem.
I have a structure. I have a list of these structures. Inside each
structure, I have two members: a list of strings, and a string.
I have made a sample program below that exhibits the error I am
having. I also read about Valgrind, and used it to tell me where I
was getting the segmentation fault,...
|
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...
|
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: 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: 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
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |