How I can pass a 2-dimensional array to a function.
The size of the array(m-by-n) is not the same each time I run the program...
How I can pass a 2-dimensional array to a function.
The size of the array(m-by-n) is not the same each time I run the program...
C.B.Ashesh,
Hyderabad, India
I've asked this before...
Unless the size of it is constant, you're better off putting it into a struct and passing that.
The size of the array is not constant and changes dynamically...
C.B.Ashesh,
Hyderabad, India
There aren't dynamicly sized arrays in C. (IE: You do not have valid C code.) Use malloc to malloc blocks of memory and just pass a pointer to said block.Originally posted by ashesh
The size of the array is not constant and changes dynamically...
If in doubt, post your code example.
Quzah.
Hope is the first step on the road to disappointment.
main() {
int *x;
int r,c,i,j;
printf("\nEnter r and c ");
scanf("%d%d",&r,&c);
x = (int *)malloc(sizeof(int)*r*c);
for(i=0;i<r;i++)
for(j=0;j<c;j++)
scanf("%d",&x[i*r+j]);
fun(x,r,c);
printf("\n");
}
fun(int *x,int r,int c){
int i,j;
for(i=0;i<r;i++)
for(j=0;j<c;j++)
printf("%d\t",x[i*r+j]);
}
The above program works for a r-by-c matrix...
C.B.Ashesh,
Hyderabad, India