pointer 2d array

This is a discussion on pointer 2d array within the C Programming forums, part of the General Programming Boards category; im having trouble compiling this, Code: #include <stdio.h> #include <math.h> double matnorm1(double **A, int m, int n) { double norm=0.0; ...

  1. #1
    Registered User
    Join Date
    Sep 2005
    Posts
    9

    pointer 2d array

    im having trouble compiling this,

    Code:
    #include <stdio.h>
    #include <math.h>
    
    double matnorm1(double **A, int m, int n)
    {
    	double norm=0.0;
    	double temp;
    	int x;
    	int y;
    	for (x=0; x<n; x++)
    	{
    		temp=0.0;
    		for (y=0; y<m; y++)
    		{
    		temp=temp+fabs(A[y][x]);
    		}
    		if(temp>norm) norm=temp; 
    	}
    	return(norm);
    }
    
    double matnorminf(double **A, int m, int n)
    {
    	double norm=0.0;
    	double temp;
    	int x;
    	int y;
    	for (x=0; x<m; x++)
    	{
    		temp=0.0;
    		for (y=0; y<n; y++)
    		{
    		temp=temp+fabs(A[x][y]);
    		}
    		if(temp>norm) norm=temp; 
    	}
    	return(norm);
    }
    
    
    main()
    {
    	double A[2][2]={{1.0,2.0},{3.0,4.0}};
    	printf("The matnorm1 is %g\n",matnorm1(A,2,2));
    	printf("The matnorminf is %g\n",matnorminf(A,2,2));
    
    }

    when i do i get the following error message-

    hw2-3.c:44: error: cannot convert 'double (*)[2]' to 'double**' for argument '1' to 'double matnorm1(double**, int, int)'
    hw2-3.c:45: error: cannot convert 'double (*)[2]' to 'double**' for argument '1' to 'double matnorminf(double**, int, int)'

    and i have no idea how to correct this.
    any help would be appreciated.

  2. #2
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

  3. #3
    Registered User
    Join Date
    Sep 2005
    Posts
    9
    if i change the declarations to
    Code:
    double matnorm1(double A[][2], int m, int n);
    then it works for the 2x2 matrix in main, but i want it to flexible to handle any matrix specified as mxn

  4. #4
    Just Lurking Dave_Sinkula's Avatar
    Join Date
    Oct 2002
    Posts
    5,006
    7. It is easier to write an incorrect program than understand a correct one.
    40. There are two ways to write error-free programs; only the third one works.*

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 2D array pointer
    By taurus in forum C Programming
    Replies: 15
    Last Post: 10-30-2008, 12:30 PM
  2. Dynamic pointer array in C
    By MacFromOK in forum Windows Programming
    Replies: 14
    Last Post: 04-09-2005, 06:14 AM
  3. Help with an Array
    By omalleys in forum C Programming
    Replies: 1
    Last Post: 07-01-2002, 08:31 AM
  4. Contest Results - May 27, 2002
    By ygfperson in forum A Brief History of Cprogramming.com
    Replies: 18
    Last Post: 06-18-2002, 01:27 PM
  5. Hi, could someone help me with arrays?
    By goodn in forum C Programming
    Replies: 20
    Last Post: 10-18-2001, 09:48 AM

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