unknown row but constant column

Viewed 38

i need to make a function that take an int matrix of known columns but varies rows which will be used later in sorting and checking if the matrix is row-magic/column magic I know how to do the sorting, and everything else but my issue is setting the end of my loops because they could be either 4/5/6 Note: I am a student so they don't expect me to use sizeof

int sort(int A[? ][5]) {
    int i, j, temp;
    for (i = 0; i < ? ; i++) { // the number of rows 

        int min = A[i][0];
        for (j = 0; j < 5; j++) { //the number of columns 
            temp = A[i][j];
            if (min > temp) {
                int swap = min;
                min = temp;
                temp = swap;

            }
        }
        int swap = A[i + 1][0];
        if (swap < A[i][5]) {
            int swap1 = A[i][5];
            swap = A[i][5];
            swap1 = A[i + 1][0;]

        }
    }
}
1 Answers

The array A decays to a pointer when it's passed to the function and a pointer doesn't contain any information about the size. You have to pass the number of rows as additional function argument:

int sort(int A[][5], int rows)
Related