Solved

Passing a Multidimensional array in a function (NOT MFC)

Posted on 2003-10-30
7
300 Views
Last Modified: 2012-05-04
HELP !!!!!

I have 2 modules, module 1 creates and populates a tree view and module 2 scans the network and store the results in a mutlidimensional array. How can i pass the  array created in module 2 to module 1 ????

This is my array:
char str_Array[10][512]; Defined golbally in module 2

Module 1: Creates Tree View
static BOOL PopulateTreeItems(HWND hWndTreeView)

Module 2: Scans network

int scanNetworkNow(HWND hWnd)


I'm developing in eVC++ (NOT MFC)
0
Comment
Question by:LPlate
  • 3
  • 2
7 Comments
 
LVL 16

Expert Comment

by:imladris
ID: 9651875
If str_Array is defined globally in module 2, then module 1 should be able to access it if you give it an extern reference like:

extern char str_Array[10][512];

outside of any function.
0
 
LVL 14

Accepted Solution

by:
Farzad Akbarnejad earned 125 total points
ID: 9652208
Hello,

I have a example for passing two-dim array to function. I got it from Denis Ritchi's book and add code to it.

-FA

// CODE CODE CODE CODE

#include <iostream.h>
void print_m34(int m[3][4]);
void print_mi4(int m[][4], int dim1);
// void print_mij_v1(int m[][], int dim1, int dim2); // error
void print_mij_v2(int** m, int dim1, int dim2);

void main()
{
      int n[3][4] = { {11,12,13,14},
                              {15,16,17,18},
                              {19,20,21,22} };

      int iTest = 0;
      
      cout << "two-dimensional array\n\n";
      print_m34(n);
      print_mi4(n,3);
      // print_mij_v1(n,3,4);
      print_mij_v2((int**)n,3,4);
      iTest = n[0][0];
      cout << "\n\n" << iTest << '\n';

      return;
}

void print_m34(int m[3][4])
{
      cout << "in print_m34 function:\n";
      for (int i = 0; i<3; i++)
      {
            for (int j = 0; j<4; j++)
            {
                  cout << ' ' << m[i][j];
            }
            cout << '\n';
      }
}

void print_mi4(int m[][4], int dim1)
{
      cout << "in print_mi4 function:\n";
      for (int i = 0; i<dim1; i++)
      {
            for (int j = 0; j<4; j++)
            {
                  cout << ' ' << m[i][j];
            }
            cout << '\n';
      }
}

/*
void print_mij_v1(int m[][], int dim1, int dim2)  // error
{
      cout << "in print_mij_v1 function:\n";
      for (int i = 0; i<dim1; i++)
      {
            for (int j = 0; j<dim2; j++)
            {
                  cout << ' ' << m[i][j];            // surprise
            }
            cout << '\n';
      }
}

*/

void print_mij_v2(int** m, int dim1, int dim2)
{
      cout << "in print_mij_v2 function:\n";
      for (int i = 0; i<dim1; i++)
      {
            for (int j = 0; j<dim2; j++)
            {
                  cout << ' ' << ((int*)m)[i*dim2+j];            // obscure
            }
            cout << '\n';
      }
}

// END CODE
0
 
LVL 16

Expert Comment

by:imladris
ID: 9658694
Did either of those answers help you?

If so, it is now time to select one and grade it to close the question.

If not, perhaps a clarifying question will help.
0
 
LVL 14

Expert Comment

by:Farzad Akbarnejad
ID: 10431764
LPlate,
Did these answers solve your problem? We are ready to help you ;)

-FA
0
 
LVL 14

Expert Comment

by:Farzad Akbarnejad
ID: 10467581
I think that I answered this question. If this answer didn't help you please post your comments or problem.

-FA
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Unlike C#, C++ doesn't have native support for sealing classes (so they cannot be sub-classed). At the cost of a virtual base class pointer it is possible to implement a pseudo sealing mechanism The trick is to virtually inherit from a base class…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now