簡體   English   中英

將一個結構數組復制到另一個較小的結構數組

[英]Copy a struct array to another struct array that is smaller

我的結構體數組有5個插槽

struct router* router[5];

可以說其中有元素,然后我

router[3] = NULL;

是否可以重新排列陣列,以使router [4]中的元素上移到router [3],router [5]移到router [4]等?

嘗試這個

void delete(struct router** router, int which, int size) {
    int i;
    // If these pointers have no other references to them then
    // Then you should free the one being deleted at this point
    for(i = which; i < size - 1; i++) {
       router[i] = router[i + 1];
    }
    router[i] = NULL;

}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM