2013-12-08 138 views
0

我有这个问题与第43行,我不知道为什么错误行:43编译器:预期标识符或“(”前“[”令牌

,如果我不写这条线,误差不会出现,我已经看到了一段代码,我还没有发现它为什么会出现

的错误是在这里

/*for(i=0;i<MAX_ESTACIONES;i++){ 
     Estaciones[i].nobici=10;  //the problem is this line 
    } 
*/ 

,这是代码

#include<stdio.h> 

#include<time.h> 

#define MAX_ESTACIONES 10 
#define MAX_CARACTERES 40 
#define MIN_CARACTERES 20 

typedef char tipodato; 
typedef struct info 
{ 
    tipodato nombre[MAX_CARACTERES]; 
    tipodato edad[MIN_CARACTERES]; 
    tipodato sexo[MIN_CARACTERES]; 
    tipodato curp[MIN_CARACTERES]; 
    tipodato domicilio[MAX_CARACTERES]; 
    tipodato nacimiento[MAX_CARACTERES]; 
    tipodato comentario[MAX_CARACTERES]; 
    tipodato contrasenia[MAX_CARACTERES]; 
    int prestamo; 
    struct info *sig; 
}Persona; 

typedef struct 
{ 
    int nobici; 
    clock_t inicio,fin; 
} Estaciones[MAX_ESTACIONES]; 

typedef Persona *Listapersona; 
Listapersona L; 


int main() 
{ 
    Persona *posicion; 
    Persona *P; 
    P=NULL; 
    posicion=NULL; 
    int opcion,salir,i; 
    salir=0; 
    for(i=0;i<MAX_ESTACIONES;i++){ 
     Estaciones[i].nobici=10;  //the problem is this line 
    } 
    return 0; 
} 
+0

您正在使用哪个IDE? – Netherwire

+2

从第二个'struct'摆脱'typedef' – P0W

+0

我正在使用CodeBlocks – Isidro

回答

8

typedef使得Estaciones的一个类型的名称,而不是你预期的变量:

typedef struct 
{ 
    int nobici; 
    clock_t inicio,fin; 
} Estaciones[MAX_ESTACIONES]; 

取出typedef使它成为一个变量,或使双方类型和变量:

typedef struct 
{ 
    int nobici; 
    clock_t inicio,fin; 
} TheStructName; 

TheStructName Estaciones[MAX_ESTACIONES]; 
+0

谢谢,现在我明白了:) – Isidro

3

删除typedef struct ... Estaciones[...]中的typedef。显然,您试图将Estaciones定义为一个类型,并将其用作变量。另外,现在应该使用struct Name { ... };,而不是使用typedef struct { ... } Name;

+0

谢谢:)现在我明白了更多 – Isidro

相关问题