![]() |
| | #1 |
| Registered User Join Date: Oct 2008
Posts: 98
| Storing an array of structures? Also how can I call a structure from an array once I have them in there? |
| Sparrowhawk is offline | |
| | #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 | |
| | #3 | |
| Registered User Join Date: Oct 2008
Posts: 98
| Quote:
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};
Code: double main (void)
{
Operator op[12]={mult, add, neg};
}
| |
| Sparrowhawk is offline | |
| | #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 | |
| | #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:
| |
| Elysia is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
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 |