作者Carbontube (碳管)
看板C_and_CPP
標題[問題] 請問要怎樣在function中對2個array做初使化?
時間Sat Feb 28 14:55:59 2009
原本這樣可以:
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
1F:推 TroyLee:參數要帶 ** 02/28 15:01
2F:推 csihcs:for C++ : void init(int n,double *&t ,double *&y) 03/01 10:21
3F:→ csihcs:其餘不變 03/01 10:21
4F:→ csihcs:for C : void init(int n,double **t , double **y) 03/01 10:22
5F:→ csihcs:init(n, &t , &y); 03/01 10:22
6F:→ csihcs:*t = (double*)calloc(n,sizeof(double)); 03/01 10:23
7F:推 aaa12345:for csihcs: if C++,t =(double*)calloc(n,sizeof(do.. 03/01 16:00
8F:→ aaa12345:u say "其餘不變" sorry! sorry! u are right! 03/01 16:02