我有一个程序,需要我将大量数据读入字符串数组,并且初始函数有一个集合部分来声明所有变量。问题是直到函数的后面我才知道字符串数组的实际大小,所以不要在找到数组长度的行下方声明它;我想定义上面的变量,然后在行后分配内存。我的想法是:
理想的:
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!