我是 C 的初学者,我只有 13 年,所以我很确定这个错误是非常基本的。
我在学校很无聊,我开始写关于“游戏”的C。
这是它:
#include <stdio.h>
#include <stdlib.h>
typedef struct {
int * id;
int * posx;
int * posy;
char * name;
} entity;
int allocData(&entity) {
entity->id = malloc(sizeof(int));
if(entity->id == NULL) {
return 1;
}
entity->posx = malloc(sizeof(int));
if(entity->posx == NULL) {
return ;
}
entity->posy = malloc(sizeof(int));
if(entity->posy = NULL) {
return 1;
}
entity->name = malloc(sizeof(char) * 129);
if(entity->name == NULL) {
return 1;
}
return 0;
}
int main() {
entity player;
allocData(&player);
player.id = 0;
player.name = "loopback\0";
printf("ID: %d, Name: %s", player.id, player.name);
return 0;
}
但是 GCC 提示。
main.c:11:15: error: expected declaration specifiers or ‘...’ before ‘&’ token
int allocData(&entity) {
^
我找不到错误,我不想在这里发帖,我确定我错过了一些愚蠢的事情。
最佳答案
您的函数定义应将指针作为参数:
int allocData(entity *player);
关于c - ‘...’ token 之前的预期声明说明符或 ‘&’,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35952154/