|
-
February 23rd, 2009, 05:31 PM
#1
passing pointers of array to function
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?
thanks
-maze
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|