Storing an array of structures?

This is a discussion on Storing an array of structures? within the C Programming forums, part of the General Programming Boards category; What's the proper specification for an array of structures? Also how can I call a structure from an array once ...

  1. #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?

  2. #2
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,047
    Just like you would declare an array of ints for ex. except that each element is of the type struct instead of an int.

  3. #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... ?

  4. #4
    Registered User
    Join Date
    Oct 2008
    Location
    TX
    Posts
    2,047
    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 10:20 PM.

  5. #5
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,765
    main returns int, always. Not double, not void, not something else.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Reading the file, and filling the array of structures
    By BlackOps in forum C Programming
    Replies: 13
    Last Post: 07-12-2009, 02:03 PM
  2. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  3. filling an array of structures?
    By voodoo3182 in forum C Programming
    Replies: 9
    Last Post: 08-06-2005, 05:29 PM
  4. array of structures help!
    By voodoo3182 in forum C Programming
    Replies: 12
    Last Post: 08-03-2005, 02:58 PM
  5. Class Template Trouble
    By pliang in forum C++ Programming
    Replies: 4
    Last Post: 04-21-2005, 04:15 AM

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