2

GCC keeps telling me:

expected ‘)’ before ‘;’ token,
expected primary-expression before ‘)’ token
expected ‘;’ before ‘)’ token

And I could not find the problem. Here is the function that have the problem:

void prim(){
    prepararEstructuras();
    int min,k;  
    for(int i=1;i<nnodos;i++){
        min = menorCoste[1];
        k = 1;
        for(int j=2;i<nnodos;j++)
            if(menorCoste[j] < min){
                min = menorCoste[j];
                k = j;
            }
        solucion[k][masCercano[k]] = G[k][masCercano[k]];
        menorCoste[k] = infinito;
        for(int j=1;j<nnodos;j++)
            if(G[k][j] < menorCoste[j] && menorCoste[j]!=infinito){
                menorCoste[j] = G[k][j];
                masCercano[j] = k;
            }                   
    }
}

Here is the line that cause the problem:

if(G[k][j] < menorCoste[j] && menorCoste[j]!=infinito){

And here are my variables:

#define MAX_NODOS 20000
#define infinito 10000;

int nnodos;
int nAristas;
int G[MAX_NODOS][MAX_NODOS]; 
int solucion[MAX_NODOS][MAX_NODOS];
int menorCoste[MAX_NODOS];
int masCercano[MAX_NODOS];
Andrew Marshall
  • 95,083
  • 20
  • 220
  • 214
Youssef Khloufi
  • 685
  • 3
  • 13
  • 24
  • What effect does this macro have on that line? #define infinito 10000; –  Jan 02 '12 at 01:08
  • 2
    While what you have is valid, I highly suggest putting those `{}` around those multi-line `for` loops, it's more difficult to read and easier to mess things up. – Andrew Marshall Jan 02 '12 at 01:11

2 Answers2

12

You have an extra semicolon in your macro.

#define infinito 10000;
                      ^

Get rid of it.

As it is, your line gets expanded to this:

if(G[k][j] < menorCoste[j] && menorCoste[j]!=10000;){
                                                  ^ does not belong here

Alternatively, don't use macros at all:

const int MAX_NODOS = 20000;
const int infinito = 10000;
Mysticial
  • 464,885
  • 45
  • 335
  • 332
2

Please, learn to use a GOOD STYLE. Omitting brackets in outer statements (e.g. statements that contain other statements) is an extraordinarily BAD style.

However, your actual bug lies in some pre-processor statement and its resulting code: #define infinito 10000; results in an extra semi-colon in-between an expression where you do not expect such an additional expression. Particularly where you will not expect a semi-colon at all.

Frunsi
  • 7,099
  • 5
  • 36
  • 42