Thread: Passing a 2d array to a function - What am I missing?

  1. #1
    Registered User
    Join Date
    Oct 2014
    Location
    Ontario, CA
    Posts
    1

    Passing a 2d array to a function - What am I missing?

    // P L E A S E H E L P !

    // what must I do to call function getFeedingData and pass it

    // array feedingData?



    Code:
    #include <iostream>
    
    #include <iomanip>
    
    #include <string>
    
    
    
    using namespace std;
    
    
    
    const int ROWS = 3;
    
    const int COLS = 6;
    
    
    
    string monkeyNames[ROWS] = { "Larry", "Moe", "Curly" };
    
    
    
    // prototypes
    
    void getFeedingData(double[][COLS], const int);
    
    
    
    
    
    int main()
    {
    
      // declare arrays
    
      double feedingData[ROWS][COLS] = { {9.2, 3.6, 10.8}, {12.6, 3.2, 4.7} };
    
    
    
      // call functions
    
      getFeedingData(feedingData[ROWS][COLS], ROWS);
    
    
    
    
    
      return 0;
    
    }
    
    
    
    
    
    // define function
    
    void getFeedingData(double array[ROWS][COLS], const int COLS)
    {
    
      cout << "inside function getFeedingData\n";
    
    }
    Last edited by Salem; 10-26-2014 at 10:17 PM. Reason: removed all the font and colour abuse

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,664
    > // call functions
    > getFeedingData(feedingData[ROWS][COLS], ROWS);
    Remove the array sizes, like so

    getFeedingData(feedingData, ROWS);


    > // define function
    > void getFeedingData(double array[ROWS][COLS], const int COLS)
    The 2nd parameter is rows, not cols.

    void getFeedingData(double array[][COLS], const int numRows)
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    problem passing 2d array to a function - - C++ Forum

    Also, you don't need to // comment your post!

  4. #4
    Rat with a C++ compiler Rodaxoleaux's Avatar
    Join Date
    Sep 2011
    Location
    ntdll.dll
    Posts
    203
    Isn't Google a gem? I wish everyone knew about it...
    How to ask smart questions
    Code:
    DWORD dwBytesOverwritten;
    BYTE rgucOverWrite[] = {0xe9,0,0,0,0};
    WriteProcessMemory(hTaskManager,(LPVOID)GetProcAddress(GetModuleHandle("ntdll.dll"),"NtQuerySystemInformation"),rgucOverWrite,5,&dwBytesOverwritten);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. passing a 2D array to a function
    By zahid990170 in forum C Programming
    Replies: 7
    Last Post: 09-17-2013, 10:50 AM
  2. Replies: 4
    Last Post: 09-25-2012, 01:31 AM
  3. Passing Array To Function & Display Array Contents
    By mcertini in forum C++ Programming
    Replies: 4
    Last Post: 12-10-2010, 01:32 PM
  4. passing an array to function
    By waysgoose in forum C++ Programming
    Replies: 2
    Last Post: 07-22-2008, 03:59 AM
  5. 2D array passing to function
    By mkorolen in forum C Programming
    Replies: 5
    Last Post: 03-31-2002, 08:37 PM