?
Solved

Passing a Multidimensional array in a function (NOT MFC)

Posted on 2003-10-30
7
Medium Priority
?
328 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 500 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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Introduction This article is the first in a series of articles about the C/C++ Visual Studio Express debugger.  It provides a quick start guide in using the debugger. Part 2 focuses on additional topics in breakpoints.  Lastly, Part 3 focuses on th…
This article shows you how to optimize memory allocations in C++ using placement new. Applicable especially to usecases dealing with creation of large number of objects. A brief on problem: Lets take example problem for simplicity: - I have a G…
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.

752 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