Hello everyone,
ive been googleing this all day and havent found an answer yet.
i want to create an array in int Main() and then pass a pointer referencing the
array to a function to fill it.
This is how far i have gotten:
Code:
int main(void)
{
test();
float dat[1000];
readnprint(&dat[0]);
/*
other code her
*/
}
void readnprint(float *base_ptr)
{
//init ifstream etc etc..
float addr=base_ptr;
while (!ins.eof())
{
ins>>x;
float f;
if(from_string<float>(f, string(x), dec)) //parse float?
{
addr=(base_ptr)+(sizeof(float)*cnt) //steps through array by sizeof(float)
*(float)addr=f; //have this assign the value to memory location (problem)
}
else
{
cout << "from_string failed" << endl;
}
cnt++;
}
ins.close();
}
im sure im just tired and not thinking right, does anyone have a better/working way of doing this?
im sure im just tired and not thinking right, does anyone have a better/working way of doing this?
Why are you working with arrays? A proper container (e.g., std::vector) is more robust and safer.
As for the other part of your problem, this is easily solvable with std::generate and a functor.
Bookmarks