8 Replies - 3480 Views - Last Post: 29 August 2010 - 04:48 AM Rate Topic: -----

#1 Guest_Avi1990*


Reputation:

Double Pointer Array

Posted 28 August 2010 - 09:34 PM

i have declared following function:

void foo(char**,int s)
{

}


and i am not able to pass 2D array... why so?.it show error to pass argument char** not char[][].

my main function

int main(){

Char array[4][4]={ {‘a’,’a’,’a’,’a’},
{‘a’,’a’,’a’,’a’},
{‘a’,’a’,’a’,’a’},
{‘a’,’a’,’a’,’a’}
}
      foo(array,4);

}

This post has been edited by JackOfAllTrades: 29 August 2010 - 04:44 AM
Reason for edit:: Added code tags.


Is This A Good Question/Topic? 0

Replies To: Double Pointer Array

#2 guahguahmonster  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 68
  • View blog
  • Posts: 209
  • Joined: 29-August 07

Re: Double Pointer Array

Posted 28 August 2010 - 09:41 PM

Hello.

Please use code tags.

The answer to your question:
C FAQ Question 6.18
C FAQ Question 6.19

This post has been edited by guahguahmonster: 28 August 2010 - 09:41 PM

Was This Post Helpful? 2
  • +
  • -

#3 Guest_Avi1990*


Reputation:

Re: Double Pointer Array

Posted 29 August 2010 - 01:11 AM

this is my program. it show error. tell me how to pass two dimensional array, Array2D to display function in below code. i can't change the display function heading. i have to pass array to display function through pointer to pointer.

#include <iostream>
using namespace std;
void Display(char**);

int main()
{
    char Array2D[6][6]={
                {'#','#','#','#','#','#'},
                {'#','0','0','0','#','#'},
                {'0','0','#','0','#','#'},
                {'#','#','#','0','#','#'},
                {'#','#','#','0','0','0'},
                {'#','#','#','#','#','#'}
                };

    Display(Array2D);
    return 0;
}

void Display(char** arr)
{
}

This post has been edited by JackOfAllTrades: 29 August 2010 - 04:47 AM
Reason for edit:: Added code tags.

Was This Post Helpful? 0

#4 janotte  Icon User is offline

  • code > sword
  • member icon

Reputation: 990
  • View blog
  • Posts: 5,141
  • Joined: 28-September 06

Re: Double Pointer Array

Posted 29 August 2010 - 01:17 AM

Welcome to DIC!

Please edit your posting (see the "EDIT" button in lower right).
( a ) Delete all your code.
( b ) Get a fresh copy of the code with formatting in place from your editor / IDE.
( c ) Paste the formatted code between code tags like this :code:
( d ) Use the "Preview Post" button to check it's all good.
( e ) Use the "Submit Modified Post" button to finish the editing.

Please give us some more details of your problem.
( a ) Does your code compile?
( b ) Any errors or warnings? If there are then share them with us.
( c ) Is the program producing any output?
( d ) How is the actual output different to what you want / expect? Give details and, ideally, examples.
Was This Post Helpful? 1
  • +
  • -

#5 guahguahmonster  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 68
  • View blog
  • Posts: 209
  • Joined: 29-August 07

Re: Double Pointer Array

Posted 29 August 2010 - 01:50 AM

Greetings.

Did you happen to post a duplicate thread ...? You realize I already answered your question in your previous thread? Copied for reference.

View Postguahguahmonster, on 28 August 2010 - 10:41 PM, said:

Hello.

Please use code tags.

The answer to your question:
C FAQ Question 6.18
C FAQ Question 6.19

This post has been edited by guahguahmonster: 29 August 2010 - 01:54 AM

Was This Post Helpful? 0
  • +
  • -

#6 Guest_Avi1990*


Reputation:

Re: Double Pointer Array

Posted 29 August 2010 - 03:41 AM

This is my program. it show error. tell me how to pass two dimensional array, Array2D to display function in below code. i can't change the display function heading. i have to pass array to display function through pointer to pointer. i tried link sent to me before but that's not helping.

And i am getting this error.

main.cpp|79|error: cannot convert `char (*)[6]' to `char**' for argument `1' to `void Display(char**)'|


#include <iostream>
using namespace std;
void Display(char**);

int main()
{
    char Array2D[6][6]={
    {'#','#','#','#','#','#'},
    {'#','0','0','0','#','#'},
    {'0','0','#','0','#','#'},
    {'#','#','#','0','#','#'},
    {'#','#','#','0','0','0'},
    {'#','#','#','#','#','#'}
    };

    Display(Array2D);
    return 0;
}

void Display(char** arr)
{
}


Was This Post Helpful? 0

#7 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5801
  • View blog
  • Posts: 12,636
  • Joined: 16-October 07

Re: Double Pointer Array

Posted 29 August 2010 - 04:09 AM

I considered ignoring or locking this, since you've already posted it, twice.

The answer is that char var[][] is simply not the same as char **. If you wish to treat it as a 2D array, you must provide the second dimension in the call.

e.g.
void Display(char arr[][6])



Yes, that's sloppy and not very modular, but so are 2D arrays. Another option is to make a struct or class to pass the data that contains the dimension information.

If you give any kind of good faith effort, I'd be happy to show you.
Was This Post Helpful? 0
  • +
  • -

#8 Guest_Avi1990*


Reputation:

Re: Double Pointer Array

Posted 29 August 2010 - 04:20 AM

thanks its working.....if i need more help i will ask.

View Postbaavgai, on 29 August 2010 - 03:09 AM, said:

I considered ignoring or locking this, since you've already posted it, twice.

The answer is that char var[][] is simply not the same as char **. If you wish to treat it as a 2D array, you must provide the second dimension in the call.

e.g.
void Display(char arr[][6])



Yes, that's sloppy and not very modular, but so are 2D arrays. Another option is to make a struct or class to pass the data that contains the dimension information.

If you give any kind of good faith effort, I'd be happy to show you.

Was This Post Helpful? 0

#9 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6058
  • View blog
  • Posts: 23,495
  • Joined: 23-August 08

Re: Double Pointer Array

Posted 29 August 2010 - 04:48 AM

Merged multiple duplicates. Please do not create duplicate topics.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1