help Passing matrix to a function

This is a discussion on help Passing matrix to a function within the C Programming forums, part of the General Programming Boards category; Hi everyone, i've got a problem passing a matrix to a function in order to print it out, in fact ...

  1. #1
    Registered User
    Join Date
    Nov 2009
    Location
    Italy
    Posts
    65

    Exclamation help Passing matrix to a function

    Hi everyone, i've got a problem passing a matrix to a function in order to print it out, in fact everytime that i try to execute the program i get this warning:
    Code:
    prova.c:11: warning: passing argument 1 of ‘display’ from incompatible pointer type
    anyway the matrix gets printed well:
    Code:
    ./a.out
    2 24 445 33 
    0 2 33 31 
    55 3 19 11 
    12 14 22 34
    can someone explain me the meaning of that warning? this is the code:
    Code:
    #include <stdio.h>
    void display(int *q, int row, int column);
    int main()
    {
    	int matrix[4][4] = {    2, 24, 445, 33,
    					  0,	 2,  33,	31,
    					  55, 3,  19, 11,
    					  12, 14, 22, 34  };
    								   			   
    	display(matrix, 4, 4);
    
    	return 0;
    }
    void display(int *q, int row, int column)
    {
    	int i, j;
    	
    	for(i = 0; i < row; i++)
    	{
    		for(j = 0; j < column; j++)
    		{
    			printf("%d ", *(q + i * column + j));
    		}
    		printf("\n");
    	}
    	printf("\n");
    }

  2. #2
    Registered User
    Join Date
    Oct 2009
    Location
    While(1)
    Posts
    377
    Quote Originally Posted by rob90 View Post
    Hi everyone, i've got a problem passing a matrix to a function in order to print it out, in fact everytime that i try to execute the program i get this warning:
    Code:
    prova.c:11: warning: passing argument 1 of ‘display’ from incompatible pointer type
    anyway the matrix gets printed well:
    Code:
    ./a.out
    2 24 445 33 
    0 2 33 31 
    55 3 19 11 
    12 14 22 34
    can someone explain me the meaning of that warning? this is the code:
    Code:
    #include <stdio.h>
    void display(int *q, int row, int column);
    int main()
    {
    	int matrix[4][4] = {    2, 24, 445, 33,
    					  0,	 2,  33,	31,
    					  55, 3,  19, 11,
    					  12, 14, 22, 34  };
    								   			   
    	display(matrix, 4, 4);
    
    	return 0;
    }
    void display(int *q, int row, int column)
    {
    	int i, j;
    	
    	for(i = 0; i < row; i++)
    	{
    		for(j = 0; j < column; j++)
    		{
    			printf("%d ", *(q + i * column + j));
    		}
    		printf("\n");
    	}
    	printf("\n");
    }
    Warning what compiler wants to say here is that there is a difference between the argument you are giving to the display function and what display function is expecting to remove the warning just modify your code like this

    Code:
    	display((int*)matrix, 4, 4);

  3. #3
    Registered User
    Join Date
    Nov 2009
    Location
    Italy
    Posts
    65
    Quote Originally Posted by RockyMarrone View Post
    Warning what compiler wants to say here is that there is a difference between the argument you are giving to the display function and what display function is expecting to remove the warning just modify your code like this

    Code:
    	display((int*)matrix, 4, 4);
    I get it, thanks for the help

  4. #4
    Registered User
    Join Date
    Oct 2009
    Location
    While(1)
    Posts
    377
    You are most welcome Enjoy C/C++ Programming

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling C in Visual Studio 2005
    By emanresu in forum C Programming
    Replies: 3
    Last Post: 11-16-2009, 04:25 AM
  2. dllimport function not allowed
    By steve1_rm in forum C++ Programming
    Replies: 5
    Last Post: 03-11-2008, 04:33 AM
  3. matrix class
    By shuo in forum C++ Programming
    Replies: 2
    Last Post: 07-13-2007, 02:03 AM
  4. Screwy Linker Error - VC2005
    By Tonto in forum C++ Programming
    Replies: 5
    Last Post: 06-19-2007, 03:39 PM
  5. Interface Question
    By smog890 in forum C Programming
    Replies: 11
    Last Post: 06-03-2002, 06:06 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21