Two-dimensional array

This is a discussion on Two-dimensional array within the C Programming forums, part of the General Programming Boards category; What is the right syntax for function prototype involved with a two-dimensional array?...

  1. #1
    Nir
    Guest

    Two-dimensional array

    What is the right syntax for function prototype involved with a two-dimensional array?

  2. #2
    Registered User Vber's Avatar
    Join Date
    Nov 2002
    Posts
    807
    Code:
    void printArray(int array[][4]); /* declare function */
    now you can pass your 2d array to this function... also pass the size to be sure you're not accessing any un-owned memory.

  3. #3
    Dev
    Dev is offline
    Registered User Dev's Avatar
    Join Date
    Mar 2003
    Posts
    59
    Or you can just pass the base address of the 2d array and number of rows and columns of that array.

    And then implement the logic to get to particular element in the array in your function.

  4. #4
    Registered User
    Join Date
    Apr 2003
    Posts
    8
    in one of my functions i create a 2 dimensional array getMessage[6][128] which is 6 lines of input going 128 characters across

    i then ask for a number to use as an encryption key

    then have to run this array through an encryption algorithm:
    encryptedcode= (i- 32 +key)%95 +32)

    then ask for the same number which will then decrypt the message.

    basically, i'm going to have to access an array i create in another function from another function. Will i need pointers to do this?

    Code:
    void encode(char getMessage[][])
    {
      int i;
    
        for (i = 0; i < getMessage[][]; i++)
        {
            if (getMessage[i] != '\n')
            {
                  getMessage[i] = (getMessage[i] - 32 +key)%95 +32);
            }
            else
                  getMessage[i] = 0;
        }
    }

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 07-11-2008, 07:39 AM
  2. two dimensional array
    By leisiminger in forum C Programming
    Replies: 12
    Last Post: 03-09-2008, 11:53 PM
  3. Type and nontype parameters w/overloading
    By Mr_LJ in forum C++ Programming
    Replies: 3
    Last Post: 01-02-2004, 12:01 AM
  4. Replies: 5
    Last Post: 11-20-2001, 11:48 AM

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