Thread: 2d array problem function receiving

  1. #1
    Registered User
    Join Date
    Apr 2016
    Posts
    21

    2d array problem function receiving

    Code:
    #include <stdio.h>
    #define N 3
    /**/
    int setMatrix(int arr[][N]);
    int checkMatrix(int arr[][N]);
    /*******************************************************************************/
    int main()
    {
        int matrix[N][N];
        setMatrix(matrix);
        puts("Checking now\n");
        checkMatrix(matrix);
    
    
        
    }
    /***********************/
    int setMatrix(int arr[][N])
    {
        int mtx[N][N];
        int i, j;
        puts("Printf please fill up the matrix\n");
        for (i = 0; i < N; i++)
            for (j = 0; j < N; j++)
            {
                puts("Enter number \n");
                scanf("%d", &mtx[i][j]);
            }
     
    
        return 0;
    }
        /*********************************/
    int checkMatrix(int arr[][N])
    {
        int i, j;
        int data[N];
        int max; // For maximum algoritm 
    /******************************************/
        for (i = 0; i < N; i++)
        {
            max = arr[i][0];
                for (j = 0; j < N; j++)
                {
                    if (arr[i][j]>max)
                        max = arr[i][j];
                }
                data[i] = max; 
        }
    /******************************************/
        printf(" Data %d %d %d \n", data[0], data[1], data[2]);
        return 0;
        }
    Need help please problem with receiving 2d arrays in functions I receive some sort of memory trash not a numbers what was implemented help please and thank you.

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    38,298
    > int mtx[N][N];
    Delete this

    > scanf("%d", &mtx[i][j]);
    Change this to use arr instead.
    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
    Apr 2016
    Posts
    21
    Quote Originally Posted by Salem View Post
    > int mtx[N][N];
    Delete this

    > scanf("%d", &mtx[i][j]);
    Change this to use arr instead.
    Thank you.
    Inshallah, shukran.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help w/ Receiving a Char Array w/ a Function
    By StevenSegal in forum C Programming
    Replies: 2
    Last Post: 10-31-2015, 01:02 PM
  2. Query: Receiving array from functions
    By wirefree101 in forum C Programming
    Replies: 4
    Last Post: 10-18-2009, 11:21 PM
  3. receiving function value which returns array of strings
    By saeed144 in forum C Programming
    Replies: 3
    Last Post: 04-27-2008, 07:54 AM
  4. Replies: 1
    Last Post: 03-21-2008, 08:15 PM
  5. Receiving an array in a function
    By hern in forum C Programming
    Replies: 3
    Last Post: 04-21-2004, 08:51 AM

Tags for this Thread