Thread: i want to print a array

  1. #1
    Registered User
    Join Date
    Aug 2006

    i want to print a array

    i have written code to print array rain[3][5], the code is like this:
    void f1(float a[][],int c);
    int main(void)
        int a;
        float *b;
        static float rain[3][5]={
        return 0;
    void f1(float a[][],int c)
         int d,d1;
         for (d=0;d<c;d++)
    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

  2. #2
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    > 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.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  3. #3
    Registered User
    Join Date
    Jun 2005
    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;
    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.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. array of pointers/pointer arithmetic
    By tlpog in forum C Programming
    Replies: 18
    Last Post: 11-09-2008, 07:14 PM
  2. Print Array in reverse order
    By swgh in forum C++ Programming
    Replies: 6
    Last Post: 11-06-2007, 01:41 PM
  3. Quick question about SIGSEGV
    By Cikotic in forum C Programming
    Replies: 30
    Last Post: 07-01-2004, 07:48 PM
  4. Replies: 10
    Last Post: 07-13-2003, 01:48 PM
  5. Creating 2D arrays on heap
    By sundeeptuteja in forum C++ Programming
    Replies: 6
    Last Post: 08-16-2002, 11:44 AM