预期标识符 - C

Expected Identifier - C

我遇到结构问题。在每个函数声明之前,我都会收到有关标识符的错误。在 'typedef'、'coords stackCreate' 和 'coords stackPush'

之前出现错误
typedef struct coords * coordPtr
{
  int x = -1;
  int y = -1;
  struct coords * next;
};

coords stackCreate(int x, int y){
  coordPtr stack = malloc(sizeof(coords));
  stack->x = x;
  stack->y = y;
  return stack;
}

coords stackPush(int x, int y, coords stack){
stack->next = malloc(sizeof(coords));
stack->next->x = x;
stack->next->y = y;
}

感谢您的帮助!

typedef struct coords * coordPtr
{
  int x = -1;
  int y = -1;
  struct coords * next;
};

应该是

typedef struct coords 
{
  int x;
  int y;
  struct coords * next;
} *coordPtr;

类型别名必须放在最后。此外,您不能在结构声明中提供默认初始值设定项。

编辑:

同样在您的程序中,您使用了两种类型的别名:coordscoordPtr。如果你想同时使用coords,你还需要:

typedef struct coords coords;