Thread: error : expected primary-expression before ']' token

  1. #1
    Registered User
    Join Date
    Feb 2013
    Posts
    54

    error : expected primary-expression before ']' token

    Hi I'm getting this error when I comipile this code :

    Code:
    #include <iostream>       // lectures et �critures (I/O)
    #include <iomanip>        // manipulation des I/O, pas besoin pour le moment
    #include <cstdlib>        // Bibliothèques C
    
    
    using namespace std;
    
    
    /****** Declarations globales ******/
    // ========= constantes ========== //
    
    
    // ============ types ============ //
    int degre_denominateur,x,y;
    float t_table2[20][20];
    
    
    // ========== variables ========== //
    
    
    // ========== fonctions ========== //
    
    
    void initialisation_grille()
    {
       float grille[20][20];
       int ligne ; int colonne ;
       for ( ligne = 0 ; ligne <= 20 ; ligne ++ )
            {  for ( colonne  = 0 ; colonne <= 20 ; colonne ++ )
                        {  grille [ ligne ] [ colonne ] = '0' ;
                            }
    
    
                    }
    }
    
    
    
    
    void affichage_grille ( float grilletest[][20]) { //grille est en entree car le SP doit connaitre
     float grille[20][20];                                       // ses valeurs pour les afficher
     int ligne ;
     int colonne ;
     for ( ligne = 20; ligne >=0 ; ligne --){
          for ( colonne = 0 ; colonne <= 20; colonne ++ ){
              cout<< grille [ ligne ] [ colonne]<< '\t';
          }
          cout << endl ;
        }
    }
    
    
    
    
    float donner_coefficients_table_de_routh__et_remplir_deux_premieres_lignes (  int x, int degre_denominateur ){
    float y;
    float t_tableaudecoefficients [25];
    int c=0;
    int l=0;
    for (x=degre_denominateur ; x>=0 ; x--){
                                    cout<<"quel est le coefficient associe au degre"<<x<<"?"<<endl;
                                    cin>> y;
                                    y = t_tableaudecoefficients[x];
                                    if ( (l==2) ){ l=0 ; c++; }
                                            t_table2[l][c] = y;
                                            l++;
                                  }
    return y;
    }
    
    
    void effectuer_calcul_table_de_routh( float t_table2toto[][20]){
    int ligne;
    int c;
    int i;
    float t_table2[20][20];
        for (ligne=0 ; ligne<=20 ; ligne++){
                    int p;
                    p=c+2;
                    for (i=2 ; i<=p ;i++ )  {
                                                int r;
                                                r=ligne-2;
                                                int s;
                                                s=ligne-1;
                                                int f;
                                                f=i+1;
    
    
                                                t_table2[ligne][i] = ( t_table2[r][f] - ( (t_table2[s][f]) * ( (t_table2[r][ligne])/(t_table2[s][ligne]) ) )  ) ;
                                               ;
                                }
    
    
        }
    
    
    }
    
    
    
    
    
    
    
    
    
    
    
    
    /******* Programme principal *******/
    
    
    int main(){
    
    
    initialisation_grille();
    affichage_grille ( t_table2[][20] );
    cout<<"quel est le degre du denominateur?"<<endl;
    cin>> degre_denominateur ;
    donner_coefficients_table_de_routh__et_remplir_deux_premieres_lignes ( x, degre_denominateur );
    effectuer_calcul_table_de_routh(t_table2[][20]);
    affichage_grille (t_table2[][20]);
    system("PAUSE");
    }
    Any help would be appreciated.

  2. #2
    Registered User
    Join Date
    Feb 2013
    Posts
    54
    At lines 117, 121, and 122

  3. #3
    Registered User
    Join Date
    Nov 2011
    Location
    Saratoga, California, USA
    Posts
    334
    Ignoring that this is C++ and not C... when you pass an entire array as an argument to a function, you pass the name only - no brackets.

  4. #4
    Registered User
    Join Date
    Feb 2013
    Posts
    54

    cannot convert 'float (*)[20]' to 'float' for argument '1' to 'void eff..(float)'

    Quote Originally Posted by Tclausex View Post
    Ignoring that this is C++ and not C... when you pass an entire array as an argument to a function, you pass the name only - no brackets.
    Ok, thank you very much,
    now i removed the brackets and i get this error when i compile :
    cannot convert 'float (*)[20]' to 'float' for argument '1' to 'void effectuer_calcul_table_de_routh(float)'

    Code:
    #include <iostream>       // lectures et �critures (I/O)
    #include <iomanip>        // manipulation des I/O, pas besoin pour le moment
    #include <cstdlib>        // Bibliothèques C
    
    
    using namespace std;
    
    
    /****** Declarations globales ******/
    // ========= constantes ========== //
    
    
    // ============ types ============ //
    int degre_denominateur,x,y;
    float t_table2[20][20];
    
    
    // ========== variables ========== //
    
    
    // ========== fonctions ========== //
    
    
    void initialisation_grille()
    {
       float grille[20][20];
       int ligne ; int colonne ;
       for ( ligne = 0 ; ligne <= 20 ; ligne ++ )
            {  for ( colonne  = 0 ; colonne <= 20 ; colonne ++ )
                        {  grille [ ligne ] [ colonne ] = '0' ;
                            }
    
    
                    }
    }
    
    
    
    
    void affichage_grille ( float grilletest ) { //grille est en entree car le SP doit connaitre
     float grille[20][20];                                       // ses valeurs pour les afficher
     int ligne ;
     int colonne ;
     for ( ligne = 20; ligne >=0 ; ligne --){
          for ( colonne = 0 ; colonne <= 20; colonne ++ ){
              cout<< grille [ ligne ] [ colonne]<< '\t';
          }
          cout << endl ;
        }
    }
    
    
    
    
    float donner_coefficients_table_de_routh__et_remplir_deux_premieres_lignes (  int x, int degre_denominateur ){
    float y;
    float t_tableaudecoefficients [25];
    int c=0;
    int l=0;
    for (x=degre_denominateur ; x>=0 ; x--){
                                    cout<<"quel est le coefficient associe au degre"<<x<<"?"<<endl;
                                    cin>> y;
                                    y = t_tableaudecoefficients[x];
                                    if ( (l==2) ){ l=0 ; c++; }
                                            t_table2[l][c] = y;
                                            l++;
                                  }
    return y;
    }
    
    
    void effectuer_calcul_table_de_routh( float t_table2toto){
    int ligne;
    int c;
    int i;
    float t_table2[20][20];
        for (ligne=0 ; ligne<=20 ; ligne++){
                    int p;
                    p=c+2;
                    for (i=2 ; i<=p ;i++ )  {
                                                int r;
                                                r=ligne-2;
                                                int s;
                                                s=ligne-1;
                                                int f;
                                                f=i+1;
    
    
                                                t_table2[ligne][i] = ( t_table2[r][f] - ( (t_table2[s][f]) * ( (t_table2[r][ligne])/(t_table2[s][ligne]) ) )  ) ;
                                               ;
                                }
    
    
        }
    
    
    }
    
    
    
    
    
    
    
    
    
    
    
    
    /******* Programme principal *******/
    
    
    int main(){
    
    
    initialisation_grille();
    affichage_grille ( t_table2 );
    cout<<"quel est le degre du denominateur?"<<endl;
    cin>> degre_denominateur ;
    donner_coefficients_table_de_routh__et_remplir_deux_premieres_lignes ( x, degre_denominateur );
    effectuer_calcul_table_de_routh(t_table2);
    affichage_grille (t_table2 );
    system("PAUSE");
    }

  5. #5
    SAMARAS std10093's Avatar
    Join Date
    Jan 2011
    Location
    Nice, France
    Posts
    2,694
    I knew that this was about to happen. What Tclausex wants to say, but is not at all specific, is that when calling the function, you should not use the brackets, but in the prototype of the function, you need them.

    Code:
    #include <stdio.h>
    
    void print(int array[], int n);
    
    int main(void)
    {
        int array[5] = {0};
        
        print(array, 5);
        
        return 0;
    }
    
    void print(int array[], int n)
    {
        int i;
        for(i = 0 ; i < n ; i++)
            printf("%d\n", array[i]);
    }
    Notice, that this forum has a thread for C++, so next time post C++ code in the c++ thread.
    Code - functions and small libraries I use


    It’s 2014 and I still use printf() for debugging.


    "Programs must be written for people to read, and only incidentally for machines to execute. " —Harold Abelson

  6. #6
    Registered User
    Join Date
    Feb 2013
    Posts
    54
    Ok thank you very much for your help, now it works. Ok next time i will post the c++ thread.

  7. #7
    Registered User
    Join Date
    Nov 2011
    Location
    Saratoga, California, USA
    Posts
    334
    I was pretty specific. I said nothing about changing the function parameters. But on looking closer, you're not even using the parameters in the functions
    Code:
    void affichage_grille ( float grilletest[][20]) { //grille est en entree car le SP doit connaitre
     float grille[20][20];                                       // ses valeurs pour les afficher
     int ligne ;
     int colonne ;
     for ( ligne = 20; ligne >=0 ; ligne --){
          for ( colonne = 0 ; colonne <= 20; colonne ++ ){
              cout<< grille [ ligne ] [ colonne]<< '\t';
          }
          cout << endl ;
        }
    }


    grilletest is un-used - so why pass the argument?


  8. #8
    Registered User
    Join Date
    Feb 2013
    Posts
    54
    you're right, i've got to pass no argument and remove grilletest which is unused

  9. #9
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,907
    Can the mods move this to the c++ thread?
    Fact - Beethoven wrote his first symphony in C

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Error: expected primary expression and ; before else
    By dragonfly22 in forum C++ Programming
    Replies: 5
    Last Post: 09-17-2012, 04:24 PM
  2. expected primary-expression before xxx token
    By lehe in forum C++ Programming
    Replies: 5
    Last Post: 07-06-2009, 02:54 PM
  3. error: expected expression before ‘{’ token
    By nendariani in forum C Programming
    Replies: 7
    Last Post: 09-14-2008, 11:27 AM
  4. expected primary expression before "." token
    By melodious in forum C++ Programming
    Replies: 4
    Last Post: 07-11-2007, 04:39 AM
  5. Expected primary expression before '<<' token...
    By RpgActioN in forum C++ Programming
    Replies: 3
    Last Post: 08-05-2005, 10:40 PM