Solved

Passing a Multidimensional array in a function (NOT MFC)

Posted on 2003-10-30
7
288 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

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
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 viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
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.

747 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

9 Experts available now in Live!

Get 1:1 Help Now