错误:令牌之前的预期标识符或'(' '='

  • 本文关键字:标识符 令牌 错误 c
  • 更新时间 :
  • 英文 :


我真的不明白为什么如果有人可以帮助我,它不起作用

我在编译时看到的内容

该函数hasard_ban返回一个与case_b(T_Tab_Case(类型相同的结构,我无法填充case_b

#include "header.h"
int main(){
int nlig, ncol, niveau, next, nban;
typedef struct T_Tab_Case case_b;
char **grille;
int     i, j;

//On demande les paramètres de la partie au joueur
parametres(&nlig, &ncol, &niveau, &next, &nban);
switch(niveau){
case 1:printf("nniveau choisi : Débutantn");break;
case 2:printf("nniveau choisi : Intermédiairen");break;
case 3:printf("nniveau choisi : Difficilen");break;
case 4:printf("nniveau choisi : Expertn");break;
};
//On génère les cases bannies
case_b = hasard_ban(nban, nlig, ncol);
i = 0;
//On alloue la mémoire suffisante pour créer notre tableau
grille = (char**)malloc(sizeof(char*) * (nlig + 2));
while (i < nlig + 1){
j = 0;
grille[i] = (char*)malloc(sizeof(char) * (ncol + 2));
while (j < ncol + 1)
{
grille[i][j] = '-';
j++;
}
i++;
}
i = 0;
while (i < case_b.n)
{
grille[case_b.tab[i].abs][case_b.tab[i].ord] = 'x'; /*les cases bannies sont représentées par des x */
i++;
}
affichage(grille);
return 0;
}

T_Tab_Case 是在 header.h 中定义的结构

T_Case表示坐标

typedef struct T_Case{
int abs;
int ord;
};
typedef struct T_Tab_Case{
struct T_Case *tab;
int n;
};

使用typedef定义类型别名具有通用语法

typedef type name;  // Define "name" to be an alias of "type"

对于结构,类型是关键字struct后跟结构标签符号,例如

typedef struct T_Case T_Case;  // Define "T_Case" to be an alias of "struct T_Case"

当您像您想要的那样组合typedef和结构定义时,也会遵循此常规语法:

// Define a structure with the tag T_Case,
// and a type-alias of that structure with the same name
typedef struct T_Case{
int abs;
int ord;
} T_Case;

正如评论中提到的,当您这样做时

typedef struct T_Tab_Case case_b;
定义符号case_b

,该符号是struct T_Tab_Case的别名。也就是说,case_b是一个类型,而不是一个可以赋值的变量。

你要么想要

struct T_Tab_Case case_b;  // Define a variable

或者,如果您已为结构创建了别名

T_Tab_Case case_b;  // Define a variable

最新更新