Thread: why i get this syntax error

  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
    28,413
    Post the smallest and simplest program that demonstrates the error.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    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,336
    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,336
    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,336
    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 02: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,336
    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.

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, 03:07 AM
  2. Testing some code, lots of errors...
    By Sparrowhawk in forum C Programming
    Replies: 48
    Last Post: 12-15-2008, 04:09 AM
  3. Game Pointer Trouble?
    By Drahcir in forum C Programming
    Replies: 8
    Last Post: 02-04-2006, 02: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, 05:27 AM