How to pass structs to functions

From: Panda2 (Panda_Mobile_2_at_hotmail.com)
Date: 02/27/05

  • Next message: Alf P. Steinbach: "Re: How to pass structs to functions"
    Date: 26 Feb 2005 18:10:32 -0800
    
    

    I hope someone can help me with this, maybe an example.. I've spent so
    long trying to work it out I'm about to lose it..

    Say I have a struct like:

    struct S1{
         int x[10];
         char y[10];
         }data[10][10];

    and i want to pass it to another function by reference (i want to
    change the values in the original function (like I said Noob!))..

    I just can't work out how to do it...

    I was thinking slong the lines of:

    #include <cstdlib>
    #include <iostream>

    using namespace std;

    void SomeFunction( don't know what to put here )
    {
        for(int a=0; a<9; a++)
        {
        or how to refer to it
        }
        return;
    }

    int main(int argc, char *argv[])
    {
      struct S1{
        int x[10];
        char y[10];
        }data[10][10];

      S1* sptr;

      SomeFunction(sptr);

      for(int x=0; x<9; x++)
      {
          cout << data[x][x].int[x] << "\n";
      }

      system("PAUSE");
      return EXIT_SUCCESS;
    }

    Maybe someone can help fill in the blanks, or offer a correct solution
    in case I'm wildly off the path.. (more than likely)


  • Next message: Alf P. Steinbach: "Re: How to pass structs to functions"