Home > Software engineering >  Error: expected declaration specifiers or ‘...’ before ‘Nanar_t’
Error: expected declaration specifiers or ‘...’ before ‘Nanar_t’

Time:12-01

here is my code, I think you will only need this piece:

struct Nanars{
    char* nom;
    int duree;
    int cote;
    int idClient;
}Nanar_t;
int trouverDureeMin(int nb, int a, Nanar_t* nana[nb]){
    int dureeMin=100;
    int indice=0;
    for(int j=0; j<nb; j  ){
        if(j!=i){
            if(nana->duree[j]>nana->duree[a] && (nana->duree[j]-nana->duree[a])<dureeMin){
                indice=j;
                dureeMin=nana->duree[j]-nana->duree[a];
            }
            else if(nana->duree[j]<nana->duree[a] && (nana->duree[a]-nana->duree[j])<dureeMin){
                indice=j;
                dureeMin=nana->duree[a]-nana->duree[j];
        }
                    
    }
    return (j);
}

I have not tried a lot but I really can not figure out the problem. I have tried to name my variables differently though which does not make any difference.

CodePudding user response:

You declared an object with the name Nanar_t of the type struct Nanars

struct Nanars{
    char* nom;
    int duree;
    int cote;
    int idClient;
}Nanar_t;

So for example this funcitondeclaration

int trouverDureeMin(int nb, int a, Nanar_t* nana[nb]){
                                   ^^^^^^^^

is invalid.

It seems you mean to declare a typedef like

typedef struct Nanars{
    char* nom;
    int duree;
    int cote;
    int idClient;
}Nanar_t;

Also it is unclear where the variable i is declare

int trouverDureeMin(int nb, int a, Nanar_t* nana[nb]){
    int dureeMin=100;
    int indice=0;
    for(int j=0; j<nb; j  ){
        if(j!=i){
        ^^^^^^^^

It seems you mean instead

        if(j!=a){

These if statements

        if(nana->duree[j]>nana->duree[a] && (nana->duree[j]-nana->duree[a])<dureeMin){
            indice=j;
            dureeMin=nana->duree[j]-nana->duree[a];
        }
        else if(nana->duree[j]<nana->duree[a] && (nana->duree[a]-nana->duree[j])<dureeMin){
            indice=j;
            dureeMin=nana->duree[a]-nana->duree[j];
    }

als0 do not make sense because the variable nana used in expressions like this nana->duree[j] has the type Nanar_t**. That is the pointer does not have the data member duree.

And returning j

return (j);

also does not make ense.

It seems you mean

return indice;

You need to rewrite the function anew. The provided code has too many bugs.

  • Related