Returning Number of Rows and Colums in a 2-D array in C

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hefty1985
    New Member
    • Jul 2007
    • 7

    Returning Number of Rows and Colums in a 2-D array in C

    Dear all,

    I hope you can help. Is any one aware of a function that would return the number of Rows and Columns of a 2-D array in C ( Matrix)?

    Or, how to go about writting a function with the Matrix as an input array and numbers of the matrix rows and columns (Similar to SIZE( ) function in MATLAB) as outputs.

    Best regards,

    BASHAR AHMAD
  • RedSon
    Recognized Expert Expert
    • Jan 2007
    • 4980

    #2
    Originally posted by hefty1985
    Dear all,

    I hope you can help. Is any one aware of a function that would return the number of Rows and Columns of a 2-D array in C ( Matrix)?

    Or, how to go about writting a function with the Matrix as an input array and numbers of the matrix rows and columns (Similar to SIZE( ) function in MATLAB) as outputs.

    Best regards,

    BASHAR AHMAD
    I don't understand your question, when you declare a 2D array you specify the number of rows and columns. [CODE=cpp]int array[10][12][/CODE] why do you need to determine the size if you already know it?

    Comment

    • hefty1985
      New Member
      • Jul 2007
      • 7

      #3
      Originally posted by RedSon
      I don't understand your question, when you declare a 2D array you specify the number of rows and columns. [CODE=cpp]int array[10][12][/CODE] why do you need to determine the size if you already know it?
      Hi,

      In case a 2-D array is to be passed to as an input to a function who declares this input parameter as a pointer. IS there a way that this function can realise the 2-D dimensions i.e. number of row and columns.

      Best Regards,
      Hefty

      Comment

      • Banfa
        Recognized Expert Expert
        • Feb 2006
        • 9067

        #4
        Originally posted by hefty1985
        In case a 2-D array is to be passed to as an input to a function who declares this input parameter as a pointer. IS there a way that this function can realise the 2-D dimensions i.e. number of row and columns.
        No, you either have to pass the width and height as parameters or if you are using C++ then you could create a class for ayour matrix and pass references to matrix objects which would know their own height and width.

        Comment

        • RedSon
          Recognized Expert Expert
          • Jan 2007
          • 4980

          #5
          Is this a homework assignment? It sounds suspiciously like another post in this forum.

          Comment

          Working...