Return a 2D array using pointers

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hanaa
    New Member
    • Nov 2007
    • 44

    Return a 2D array using pointers

    Hello

    I need to call a function that returns a 2D array. I need to dynamically allocate memory for the array in the callee. Now, I return using a pointer to a pointer.

    In the callee, I allocate the memory using mallloc, assign values to the array elements, output using printf in the callee. Eveything works fine.
    But in the caller function, I am unable to access the array elements using the pointer returned. I either get garbage values, or an access violation error or both.

    I am attaching the code. Will someone please tell me why it is not working?

    Hanaa
    Attached Files
  • hanaa
    New Member
    • Nov 2007
    • 44

    #2
    Please ignore this thread

    I am so very sorry.

    I forgot to write the return statement in the callee.

    Comment

    • Banfa
      Recognized Expert Expert
      • Feb 2006
      • 9067

      #3
      A semi decent modern compiler should issue a diagnostic about that which begs the questions

      Are you using an old compiler or have you not switched on all warnings or did you ignore the warnings?

      If it is the final case then never ignore warnings, they are there for a reason and 99% of the time you can make your code compile without warnings.

      Comment

      Working...