Solved

Passing a Multidimensional array in a function (NOT MFC)

Posted on 2003-10-30
7
324 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

What is C++ STL?: STL stands for Standard Template Library and is a part of standard C++ libraries. It contains many useful data structures (containers) and algorithms, which can spare you a lot of the time. Today we will look at the STL Vector. …
Container Orchestration platforms empower organizations to scale their apps at an exceptional rate. This is the reason numerous innovation-driven companies are moving apps to an appropriated datacenter wide platform that empowers them to scale at a …
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

688 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