Thread: Passing array of struct as a function parameter

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Dec 2007
    Posts
    30

    Passing array of struct as a function parameter

    Hello,

    I have a structure and an multidimensional array of that structure. How can I access (read and write) that array's element's fields (without defining it as a global variable) inside a function when the array is declared in main() ?

    Here's how I tried it (but failed):

    Code:
    #include <stdio.h>
    
    typedef struct { 
        double xy;
        char *message; 
    } twin;
    
    void print(twin *table, char *m, int i)
    {
        (*table[i][1]).message != m ?   <----- error: subscripted value is neither array nor pointer
            printf("\nX = &#37;f Y = %s", *table[i][0].xy, *table[i][1].message): <----- same here (twice)
            printf("\nX = %f Y = %f", *table[i][0].xy, *table[i][1].xy);   <----- same here (twice)
        return;    
    }
    
    int main()
    {    
        int i, n;
        double x, a, h;     
        char v[] = "empty";
        ...
        twin table[n-1][1];
        ...
        print(&table, &v, 1); 
      
      return 0;
    }
    Best wishes,
    Desmond5
    Last edited by desmond5; 12-04-2007 at 09:49 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Need help with linked list sorting function
    By Jaggid1x in forum C Programming
    Replies: 6
    Last Post: 06-02-2009, 02:14 AM
  2. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 03:07 AM
  3. cannot start a parameter declaration
    By Dark Nemesis in forum C++ Programming
    Replies: 6
    Last Post: 09-23-2005, 02:09 PM
  4. Passing pointers between functions
    By heygirls_uk in forum C Programming
    Replies: 5
    Last Post: 01-09-2004, 06:58 PM
  5. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM