-
i want to print a array
i have written code to print array rain[3][5], the code is like this:
Code:
#include<stdio.h>
void f1(float a[][],int c);
int main(void)
{
int a;
float *b;
static float rain[3][5]={
{10.2,8.1,6.8,4.2,1.5},
{10.2,8.1,6.8,4.2,1.5},
{10.2,8.1,6.8,4.2,1.5}};
f1(rain,3);
system("pause");
return 0;
}
void f1(float a[][],int c)
{
int d,d1;
for (d=0;d<c;d++)
{
for(d1=0;d1<5;d1++)
printf("%5.1f",a[d][d1]);
putchar('\n');
}
}
but i get a error "invalid use of array with unspecified bounds" for "printf("%5.1f",a[d][d1]);" statement. what is the problem? thanks
-
> void f1(float a[][],int c)
Change the prototype and definition to
void f1(float a[][5],int c)
It's only the left-most dimension which can be left empty.
-
timhfx, that is probably the last of a number of errors being reported by the compiler. As a rough rule you should begin by trying to address the errors a compiler reports first because errors detected later may be a side effect of previous ones.
The first errors you would have received would have been about the declaration of function f1(); when passing multi-dimensional arrays, you can get away with omitting only the first dimension: all of the others have to be specified.
In your case, f1() should presumably be declared as;
Code:
void f1(float a[][5],int c);
The implementation, which comes later on, would need to do the same thing.
Your compiler would almost certainly have complained about these first. How do I know? Because the problem with the printf() call is a side-effect of the earlier errors - despite the fact you didn't bother to look at, or give us information about, those earlier problems.