Thread: A questions about structures

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    92

    A questions about structures

    Hello I'am writing a program and I used structures to make some user defined variables. Then I passed those variables to another function where a value was assigned to them. Now I want the values of those variables to be used in another function. How do I do that?

    Below is an example of what I did.

    Code:
    
    typedef struct{
      float Fish;
      float Cotton;
      float Wood;
      float Coco;
      float Sugar;
      float Guns;
      float Textiles;
      float Tobacco;
      float Wine;
    }Goods_g;
    
    int main()
    {
       Goods_g G;
       other parts of the program is written here
    }
    
    int function(Goods_g *G)
    {
      G->Fish      = 50;
      G->Cotton = 80;
      G->Wood   = 100;
      G->Coco    = 140;
      G->Sugar = 350;
      G->Guns = 700;
      G->Textiles =1350;
      G->Tobacco =1900;
      G->Wine =2150;
    }
    
    int Another_Function()
    {
      how do I get the values of the individual elements sucn as Fish to use in this function without changing the values
    }
    
    I apologies for the vagueness of the question and the information that I provided but I want to learn how to do this. If any body can help me and point me in the right direction I will be very grateful.

  2. #2
    Woof, woof! zacs7's Avatar
    Join Date
    Mar 2007
    Location
    Australia
    Posts
    3,459
    well your asking for the address of G...

    so:

    Code:
    int main()
    {
       Goods_g G;
       function(&G);
    
    //or
        Goods_g * H;
       function(H);
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. questions about structures passing through functions
    By nareik9394 in forum C Programming
    Replies: 1
    Last Post: 03-18-2009, 06:19 PM
  2. Data structures basic questions
    By WarDoGG in forum C Programming
    Replies: 7
    Last Post: 07-11-2008, 09:42 AM
  3. A very long list of questions... maybe to long...
    By Ravens'sWrath in forum C Programming
    Replies: 16
    Last Post: 05-16-2007, 05:36 AM
  4. COntrol structures and functions questions
    By angelicscars in forum C Programming
    Replies: 1
    Last Post: 11-21-2005, 11:50 AM
  5. I have some questions about data structures and algorithms
    By Tonyukuk in forum C++ Programming
    Replies: 4
    Last Post: 03-27-2003, 01:31 PM