我遇到了結構問題。在每個函數聲明之前,我會收到有關標識符的錯誤。 '類型定義', 'COORDS stackCreate' 之前的錯誤發生, 'COORDS stackPush'預期標識符 - C
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結構COORDS * coordPtr' ---這絕對不是正確的C. – 2015-02-11 20:35:30
你嘗試過: typedef結構_coords { int x = -1; int y = -1; struct _coords * next; } coords; – madz 2015-02-11 20:36:53
這是對C語法的一個簡單誤解:'* coordPtr'在結構體之後,而不是在它之前。投票結束爲錯字。 – dasblinkenlight 2015-02-11 20:36:58