close

ArrayCopy簡介

int ArrayCopy( 
    void&        dst_array[],        //目標數組
    const void&  src_array[],    //來源數組 
    int          dst_start=0,          //寫入目標數組的指數 
    int          src_start=0,          //來源數組的最初指數 
    int          count=WHOLE_ARRAY    //元素數量 

);

參量

dst_array[]

[out]目標數組

src_array[]

[in]來源數組 

dst_start=0

[in]從目標數組第幾位開始寫入,預設為0。

src_start=0

[in]從來源數組第幾位開始讀取,預設為0。

count=WHOLE_ARRAY

[in]元素數量,預設為複製全部(count=WHOLE_ARRAY)。



在執行以下程式後,透過ArrayCopy函數,將x數組的元素,複製到y數組中。

 

double y[];

void OnTick()
{
 
 double x[6]={100,200,300,400,500,600};

 ArrayCopy(y,x);
 
 for(int i=0; i<=5; i++) 
 {
  printf(y[i]);
 }

}

使用for迴圈輸出y數組的元素,得到的結果為100、200、300、400、500、600。

ArrayCopy00.jpg

 

如果要複製的元素數量(x)與目地數組(y)大小不符,目地數組(y)將自動增加大小(數組必須是動態的)。
 

arrow
arrow
    全站熱搜
    創作者介紹
    創作者 興小弟讀書筆記 的頭像
    興小弟讀書筆記

    興小弟讀書筆記

    興小弟讀書筆記 發表在 痞客邦 留言(0) 人氣()