我有2個結構數組容易使用多個結構數組
myStruct leds_left[20];
myStruct leds_right[20];
我需要一種方法來將兩個結構結合起來,這樣我就可以使用它像:
*(structPtr[10]) // points to element of leds_left[10]
*(structPtr[30]) // points to element of leds_right[10]
我已經嘗試過了如下:
myStruct ** structPtr = (myStruct**) malloc((20 + 20) * sizeof(myStruct*));
structPtr[0] = &leds_right[15]; //just with one element for testing
*(structPtr[0]) = newValue;
我在做什麼錯了?
它看起來像你想的結構融合在一起。看看這個答案http://stackoverflow.com/a/32315939/7255359 –
你已經有的代碼將工作,如果你指定所有的指針 –