Thread: Structures

  1. #1
    Unregistered
    Guest

    Question Structures

    I was wondering if there's a way to pass individual structure array elements to a function without using pointers. Im having some trouble with it.

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    By value? So that you're just getting the value of the data contained? Sure:
    Code:
    struct mystruct {
        int x;
    };
    
    struct mystruct myarray[5];
    
    void myfun( int someInt )
    {
        do_something( someInt );
    }
    
    To call this function and only pass it 'x', do:
    
    myfun( myarray[someValue].x );
    
    An array of pointers to structures, you'd change it to:
    
    myfun( myArray[someValue]->x );
    Quzah.
    Hope is the first step on the road to disappointment.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  2. Structures, passing array of structures to function
    By saahmed in forum C Programming
    Replies: 10
    Last Post: 04-05-2006, 11:06 PM
  3. Input output with structures
    By barim in forum C Programming
    Replies: 10
    Last Post: 04-27-2004, 08:00 PM
  4. pointers to arrays of structures
    By terryrmcgowan in forum C Programming
    Replies: 1
    Last Post: 06-25-2003, 09:04 AM
  5. Methods for Sorting Structures by Element...
    By Sebastiani in forum C Programming
    Replies: 9
    Last Post: 09-14-2001, 12:59 PM