私は C で単純なタスクに苦労してきました... (しばらく経ちました。) メモリ割り当て関数を使用せずに構造体の配列を作成およびリセットする関数を作成する必要があります。
私はもともとmallocでそれを設計しました:
typedef struct {
int ..
int ..
} Branch;
Branch* createBranchList (int N)
{
Branch *List;
Branch reSet = {0}; // a zero'd Branch struct used for the resetting process
int i;
if(!(List=(Branch*)malloc(sizeof(Branch)*N))){
printf("Allocation error");
return NULL;
}
for(i=0; i<N; i++)
List[i] = reSet;
return List;
}
メモリ割り当てを使用せずにこれを行うにはどうすればよいですか? リファレンスを返すことはできますか? 私はそうは思わない。
助けてくれてありがとう。