error correction

Discussion in 'C' started by bashamsc, Dec 11, 2007.

  1. bashamsc

    bashamsc New Member

    Joined:
    May 22, 2007
    Messages:
    51
    Likes Received:
    7
    Trophy Points:
    0
    Location:
    chennai
    Code:
    #include<stdio.h>
    #define col 3
    #define row 3
    
    void foo(int *a,int col , int row)
    {
    int i,j;
    int *a[col][row];
    for(i=0;i<col;i++)
    {
    for(j=0;j<row;i++)
    {
    printf(" %d\n",*a[i][j]);
    }
    }
    }
    
    
    main()
    {
    
    int arr[col][row] = {(1,2,3),(4,5,6),(6,7,8)};
    
    foo(&arr[0][0],col,row);
    
    }
    
    I am getting this error

    parse error before numeric constant
     
    Last edited by a moderator: Dec 11, 2007
  2. Salem

    Salem New Member

    Joined:
    Nov 15, 2007
    Messages:
    133
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Please don't PM me for 1:1 support.
    > int arr[col][row] = {(1,2,3),(4,5,6),(6,7,8)};
    All those ( ) should be { }

    > void foo(int *a,int col , int row)
    Is it your intention to "flatten" the array like this, or is it just something you figured out how to pass a 2D array into a function.

    void foo ( int a[row][col], int row, int col )
    would accept a true 2D array.


    Also, your row and col are the same names as your #defines, so the line expands to
    void foo(int *a,int 3, int 3)
    Tip: All #defines should be written in upper case, like
    #define ROW 3
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice