如何解决warring:passing arg 1 of `show' from incompatible pointer type
本帖最后由 Sheldencn 于 2013-03-19 10:34:05 编辑
//arr_copy2.c--copy two-dimensional arrayincompatible c
#include <stdio.h>
#define COLS 5//the columns of each array
#define ROWS 3//the rows of each array
void copy_arr(double source[][COLS],double target1[][COLS],int rows);//use array
void show(double arr[][COLS],int rows);//display array
int main (void)
{
double source[ROWS][COLS]={{1.1,2.2,3.3,4.4,5.5},
{2.3,13.5,24.5,5.2,8.3},
{4.23,2.4,6.2,8.7,0.5}};
double target1[ROWS][COLS];
printf("initial array is:\n");
show(source,ROWS);
copy_arr(source,target1,ROWS);
printf("copied target array1 is:\n");
show(target1,ROWS);
return 0;
}
//copy the array
void copy_arr(double source[][COLS],double target1[][COLS],int rows)
{
for(int r=0;r<rows;r++)
{
for(int c=0;c<COLS;c++)
{
target1[r][c]=source[r][c];
}
}
}
//show the array
void show(double arr[][COLS],int rows)
{
for(int r=0;r<rows;r++)
{
for(int c=0;c<COLS;c++)
{
printf("%5.1f",arr[r][c]);
}
printf("\n");
}
}
应该是const指针问题,出现警告warring:passing arg 1 of `show' from incompatible pointer type但不知道如何更改(不能删改掉show()函数中的const)
#include <stdio.h>
#define COLS 5//the columns of each array
#define ROWS 3//the rows of each array
void copy_arr(double source[][COLS],double target1[][COLS],int rows);//use array
void show(const double arr[][COLS],int rows);//display array 加了const没问题啊
int main (void)
{
double source[ROWS][COLS]={{1.1,2.2,3.3,4.4,5.5},
{2.3,13.5,24.5,5.2,8.3},
{4.23,2.4,6.2,8.7,0.5}};
double target1[ROWS][COLS];
printf("initial array is:\n");
show(source,ROWS);
copy_arr(source,target1,ROWS);
printf("copied target array1 is:\n");
show(target1,ROWS);
return 0;
}
//copy the array
void copy_arr(double source[][COLS],double target1[][COLS],int rows)
{
for(int r=0;r<rows;r++)
{
for(int c=0;c<COLS;c++)
{
target1[r][c]=source[r][c];
}
}
}
//show the array
void show(const double arr[][COLS],int rows) //加了const
{
for(int r=0;r<rows;r++)
{
for(int c=0;c<COLS;c++)
{
printf("%5.1f",arr[r][c]);
}
printf("\n");
}
}