C Board  

Go Back   C Board > General Programming Boards > C Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 12-14-2008, 10:08 PM   #1
Registered User
 
Join Date: Oct 2008
Posts: 98
Storing an array of structures?

What's the proper specification for an array of structures?

Also how can I call a structure from an array once I have them in there?
Sparrowhawk is offline   Reply With Quote
Old 12-14-2008, 10:19 PM   #2
Registered User
 
Join Date: Oct 2008
Location: TX
Posts: 1,262
Just like you would declare an array of ints for ex. except that each element is of the type struct instead of an int.
itCbitC is offline   Reply With Quote
Old 12-14-2008, 10:26 PM   #3
Registered User
 
Join Date: Oct 2008
Posts: 98
Quote:
Originally Posted by itCbitC View Post
Just like you would declare an array of ints for ex. except that each element is of the type struct instead of an int.
Ok say I have this struct..
Code:
typedef struct Operator
{
	char symbol;
	int operands;
	union
	{
		void *f;
		double (*f0)(void);
		double (*f1) (double x);
		double (*f2) (double x, double y);
	}
}Operator;

Operator mult={'*',2,multiply1};
Operator add={'+',2,add1};
Operator neg={'-',1,neg1};
Operator divide={'/',2,divide1};
Operator square={'sq',1,square1};
Operator sqrt={'sqrt',1,squareRoot1};
Operator min={'m',2,min1};
Operator max={'M',2,max1};
Operator expo={'^',2,expo1};
Operator pi={'pi',0,pi};
Operator loga={'log',1,L};
Operator expon={'e^',1,E};
So would it be like this?:

Code:
double main (void)
{
	Operator op[12]={mult, add, neg};
}
etc... ?
Sparrowhawk is offline   Reply With Quote
Old 12-14-2008, 11:00 PM   #4
Registered User
 
Join Date: Oct 2008
Location: TX
Posts: 1,262
that's exactly it and here's a good writeup on array of structures
http://faq.cprogramming.com/cgi-bin/...&id=1073086407

Last edited by itCbitC; 12-14-2008 at 11:20 PM.
itCbitC is offline   Reply With Quote
Old 12-15-2008, 03:07 AM   #5
Mysterious C++ User
 
Join Date: Oct 2007
Posts: 14,099
main returns int, always. Not double, not void, not something else.
__________________
Using: Microsoft Windows™ 7 Professional (x64), Microsoft Visual Studio™ 2008 Team System
I dedicated my life to helping others. This is only a small sample of what they said:
"Thanks Elysia. You're a programming master! How the hell do you know every thing?"
Quoted... at least once.
Quote:
Originally Posted by cpjust
If C++ is 2 steps forward from C, then I'd say Java is 1 step forward and 2 steps back.
Elysia is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Reading the file, and filling the array of structures BlackOps C Programming 13 07-12-2009 02:03 PM
Dynamic array of structures containing yet another dynamic array of structures innqubus C Programming 2 07-11-2008 07:39 AM
filling an array of structures? voodoo3182 C Programming 9 08-06-2005 05:29 PM
array of structures help! voodoo3182 C Programming 12 08-03-2005 02:58 PM
Class Template Trouble pliang C++ Programming 4 04-21-2005 04:15 AM


All times are GMT -6. The time now is 09:22 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22