[問題] 請問要怎樣在function中對2個array做初使化?

看板C_and_CPP作者 (碳管)時間16年前 (2009/02/28 06:56), 編輯推噓3(305)
留言8則, 3人參與, 最新討論串1/1
原本這樣可以: int n=100; double *t t = initialization(n) : double *intitaliztion(int n) { double *t; t = (double*)calloc(n,sizeof(double)); // 下面就設定t array的內容 return t; } === 現在若想要對兩個以上的array做初使設定: int n= 100; double *t, *y; initialization(n, t , y); void initialization(int n,double *t ,double *y) { t = (double*)calloc(n,sizeof(double)); y = (double*)calloc(n,sizeof(double)); //塞值進去t, y array中 return; } 這樣是不行的,debug mode是不會過,release mode會不正確 解決方法是把 calloc那行寫在function外面。但我就想把配置那行 寫在function中啊。。。 請問有無大牛知道要怎做呢,謝謝。 不要和我講寫兩個function。。。。 -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 218.167.75.177

02/28 15:01, , 1F
參數要帶 **
02/28 15:01, 1F

03/01 10:21, , 2F
for C++ : void init(int n,double *&t ,double *&y)
03/01 10:21, 2F

03/01 10:21, , 3F
其餘不變
03/01 10:21, 3F

03/01 10:22, , 4F
for C : void init(int n,double **t , double **y)
03/01 10:22, 4F

03/01 10:22, , 5F
init(n, &t , &y);
03/01 10:22, 5F

03/01 10:23, , 6F
*t = (double*)calloc(n,sizeof(double));
03/01 10:23, 6F

03/01 16:00, , 7F
for csihcs: if C++,t =(double*)calloc(n,sizeof(do..
03/01 16:00, 7F

03/01 16:02, , 8F
u say "其餘不變" sorry! sorry! u are right!
03/01 16:02, 8F
文章代碼(AID): #19gE00NV (C_and_CPP)