passing 2d array as pointer

This is a discussion on passing 2d array as pointer within the C Programming forums, part of the General Programming Boards category; i have a 2d array in 1 source file, and i want to pass it to a function in another ...

  1. #1
    Registered User
    Join Date
    Aug 2003
    Posts
    288

    passing 2d array as pointer

    i have a 2d array in 1 source file, and i want to pass it to a function in another file.

    heres the function i got:

    Code:
    void ProcessArray(char **pArray)
    {
          pArray[0][0] = 'a';
    }
    heres how i call it:

    Code:
    char array[50][50];
    ProcessArray(&array);
    i know its a simple question but this is pretty much my only problem with pointers.

    i even tried:


    Code:
    void ProcessArray(char ***pArray)
    {
          *pArray[0][0] = 'a';
    }
    Code:
    char array[50][50];
    ProcessArray((char ***)&array);

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,656
    Surely discussed before
    Code:
    // or void ProcessArray(char pArray[][50])
    // or void ProcessArray(char (*pArray)[50])
    // but this one's simplest - just copy/paste
    void ProcessArray(char pArray[50][50])
    {
          pArray[0][0] = 'a';
    }
    
    char array[50][50];
    ProcessArray(array);

  3. #3
    Registered User
    Join Date
    Aug 2003
    Posts
    288
    id assumed it was discussed before so i looked through the FAQ then started searching, but thanks for the reply.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problems with passing an array of structures by pointer
    By raptor1770 in forum C Programming
    Replies: 9
    Last Post: 11-29-2008, 10:01 AM
  2. Pointer to 2D array?
    By meredithm in forum C Programming
    Replies: 1
    Last Post: 10-30-2008, 01:11 PM
  3. Replies: 6
    Last Post: 11-09-2006, 02:28 AM
  4. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM
  5. sending or recieving a[][]to a function
    By arian in forum C++ Programming
    Replies: 12
    Last Post: 05-01-2004, 10:58 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21