默認結構:C結構指針
struct counter {
long long counter;
};
struct instruction {
struct counter *counter;
int repetitions;
void(*work_fn)(long long*);
};
static void increment(long long *n){
n++;
}
我行:
n = 2;
struct counter *ctest = NULL;
int i;
if(ctest = malloc(sizeof(struct counter)*n){
for(i=0; i<n ;i++){
ctest[i].counter = i;
}
for(i=0; i<n ;i++){
printf("%lld\n", ctest[i].counter);
}
}
struct instruction itest;
itest.repetitions = 10;
itest.counter = ctest; //1. This actually points itest.counter to ctest[0] right?
//2. How do I actually assign a function?
printf("%d\n", itest.repetitions);
printf("%lld\n", itest.counter.counter); // 3. How do I print the counter of ctest using itest's pointer?
所以我試圖讓這三樣東西的工作。
感謝
你會得到什麼錯誤? – Joe 2011-04-27 16:29:00
沒關係,修復了所提供的幫助中的大部分錯誤謝謝 – Jono 2011-04-27 16:40:17
P.S. @Jono它會更好地upvote有用的答案,並回答你接受:) – 2011-04-28 06:57:42