Article 55ENJ new array in a function

new array in a function

by
bkelly
from LinuxQuestions.org on (#55ENJ)
My app needs to call a function that will read some number of values from a text file and put them in the array. The count is not known until the function opens the file. The array must be new'ed within the function. What is the syntax that allows the new'ing of the array within the function. Below are some code fragments showing the concept. I know the syntax is wrong but cannot create a search function that covers new'ing the array in the function.
Code:int main( ... )
{
float test_data[ ];
int test_count;
status = get_test_data( &test_data, &test_count );
for( int i = 0; i < test_count; i ++ ) { do something with the data };
... }

bool get_test_data( &test_data, &test_count )
{...
test_count = 128; // gets set from an fscanf( ... )
test_data = new float[ test_count ];
for( j = 0; j < test_count; j ++ )
fscanf( test_data_file, "%f", test_data[ j ] );
... }latest?d=yIl2AUoC8zA latest?i=n5RBzV8AtDU:Nt-QNRtIEB8:F7zBnMy latest?i=n5RBzV8AtDU:Nt-QNRtIEB8:V_sGLiP latest?d=qj6IDK7rITs latest?i=n5RBzV8AtDU:Nt-QNRtIEB8:gIN9vFwn5RBzV8AtDU
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments