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
Solved

Passing a Multidimensional array in a function (NOT MFC)

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Article by: SunnyDark
This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
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 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 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.

840 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