大量のデータを文字列の配列に読み込む必要があるプログラムがあり、すべての変数を宣言する初期関数のセット部分があります。問題は、関数の後半まで文字列の配列の実際のサイズがわからないため、配列の長さを見つける行の下で宣言するのではなく、上記の変数を定義してから、行の後にメモリを割り当てたいと思います。私の考えは:
理想:
int declaration;
Char ** DataArray; //initial declaration at top of file
char * usage;
int Buffer;
//function continues.....
Buffer = SomeNum; //find length of array needed
//allocate ideal size of array(HOW?)
私が現在していること:
int declaration; //not placing the declaration here, bad programming practice especially
char * usage; //considering this is an open source project i am working on.
int Buffer;
//function continues.....
Buffer = SomeNum;
char * DataArray[Buffer]; //works, but NOT ideal!