[問題] 請問要怎樣在function中對2個array做初使化?
原本這樣可以:
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
03/01 10:21, 2F
→
03/01 10:21, , 3F
03/01 10:21, 3F
→
03/01 10:22, , 4F
03/01 10:22, 4F
→
03/01 10:22, , 5F
03/01 10:22, 5F
→
03/01 10:23, , 6F
03/01 10:23, 6F
推
03/01 16:00, , 7F
03/01 16:00, 7F
→
03/01 16:02, , 8F
03/01 16:02, 8F