所以我有這樣的結構:指針如何與預定義的結構進行交互?
struct state {
int previous[2];
int current[2];
bool pen;
};
typedef struct state state;
在我使用這個作爲一個參數的一些功能,例如:
void new_state(&s, char *file, int i, int j){
int new = s -> current[j];
s -> current[j] = operand(byte(i, file)) + s -> current[j];
s -> previous[j] = new;
}
我在一個函數調用這些,其中I定義S作爲前「預期的聲明說明符或「...」:從狀態:
void main_function(char *file){
state s;
display *display = newDisplay(file, 200, 200);
int j = size(file);
for(int i=0; i<j; i++){
if(opcode(byte(i, file)) == 0){
new_state(&s, file, i, 0);
}
else if(opcode(byte(i, file)) == 1){
new_state(&s, file, i, 1);
draw(s, display, file);
}
else if(opcode(byte(i, file)) == 2){
pause(display, operand(byte(i, file)) * 10);
}
else{
new_pen(s);
}
end(display);
}
}
但是,編譯我仍然得到錯誤消息時'令牌,但我不明白爲什麼。我已經將變量s定義爲結構狀態的一部分,然後通過使用& s,這給它的地址是正確的嗎?
你得到它,因爲'無效NEW_STATE(&S,字符*文件,詮釋我,詮釋J)'完成胡言亂語。函數聲明不是函數調用。 – Lundin
請注意,點'.'和箭頭' - >'運算符確實非常緊密,並且不應該在它們周圍有空格,而不像像''這樣的低優先級二元運算符,它們周圍應該有空格。是的,這是風格。除了新手代碼外,點和箭頭周圍的空格絕對不常見。 –