why i get this syntax error

This is a discussion on why i get this syntax error within the C Programming forums, part of the General Programming Boards category; in this line Code: printf("%d",mat[index][kndex]); i get |36|error: invalid use of array with unspecified bounds|...

  1. #1
    Banned
    Join Date
    Oct 2008
    Posts
    1,535

    why i get this syntax error

    in this line
    Code:
    printf("%d",mat[index][kndex]);
    i get

    |36|error: invalid use of array with unspecified bounds|

  2. #2
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Perhaps because you put a space between the first dimension, and the second.

    Santa will give you a piece of C coal for that one!

  3. #3
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    no its not a space because when i tried to delete this space i delete "]"
    there is no space between them

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,461
    Post the smallest and simplest program that demonstrates the error.
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    Code:
    void display(int mat[][],int rows,int cols){
    
        int index,kndex;
    
            for (index=0;index<rows;index++){
    
               for (kndex=0;kndex<cols;kndex++){
    
                 printf("&#37;d ",mat[index][kndex]);
               }
               printf("\n");
            }
        }//end display

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    So the error is on the line that says
    Code:
    void display(int mat[][],int rows,int cols){
    When passing arrays to a function, all dimensions (except possibly the first) must be given in the function declaration.

  7. #7
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    but my matrix size is set by the user.

    i cant put numbers in [][]

  8. #8
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    How are you declaring your matrix then? You may have to do the array indexing "by hand", then.

  9. #9
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    so in the signature i have to write something like:

    Code:
     void display(int mat[3][4],int rows,int cols){

  10. #10
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    i dont want to declare it
    i want to input a matrix with numbers that the user inputed

  11. #11
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Obviously you have to declare any variable you intend to use.

  12. #12
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    can i build a new matrix
    and make reference to the input one?

  13. #13
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    tried this still not working

    Code:
    void display(int mat[][],int rows,int cols){
    
        int index,kndex;
        int mat2[rows][cols];
    
        mat2[][]=mat[][];
    
            for (index=0;index<rows;index++){
    
               for (kndex=0;kndex<cols;kndex++){
    
                 printf("&#37;d ",mat2[index][kndex]);
               }
               printf("\n");
            }
        }//end display
    Last edited by transgalactic2; 12-18-2008 at 01:34 PM.

  14. #14
    Banned
    Join Date
    Oct 2008
    Posts
    1,535
    i get a different error

    |33|error: syntax error before ']' token|

  15. #15
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You still can't pass mat[][] into a function. If you don't know the size of the array, you can only pass it in as a pointer-to-int, not as an array.

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Compiling sample DarkGDK Program
    By Phyxashun in forum Game Programming
    Replies: 6
    Last Post: 01-27-2009, 02:07 AM
  2. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 03:09 AM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 01:53 AM
  4. ras.h errors
    By Trent_Easton in forum Windows Programming
    Replies: 8
    Last Post: 07-15-2005, 10:52 PM
  5. Linking error
    By DockyD in forum C++ Programming
    Replies: 10
    Last Post: 01-20-2003, 04:27 AM

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