基本上我想qPtr [0]舉行特徵碼[0]C編程:需要新的眼光來看待這個[!演示代碼=功課]
struct myQueue{
struct sample* node;
int front;
int size;
int numElements;
};
struct sample{
int field1[5];
char field2[10];
}
int main(){
struct myQueue* qPtr = malloc(10 * sizeof(struct myQueue);
struct sample* samplePtr = malloc(10 * sizeof(struct sample); //assume this array has been initialized
enqueue(qPtr, samplePtr[0]); //this does not work
}
//returns 1 if enqueue was successful
int enqueue(struct myQueue* qPtr, struct sample* sPtr){
qPtr->node[(qPtr->front + qPtr->numElements) % qPtr->size] = sPtr; //code pertains to circular array implementation of queues
return 1;
}
我一直在它約2小時現在,並希望澄清我在做錯在概念上。謝謝!
@jeeper_creepers - 與您的評論「認爲此陣已被初始化」,我想的'myQueue'也intialized有效值結構成員。這是你的意思嗎 ? – Mahesh 2011-03-12 07:23:23