- Oct 11, 2002
- 3,637
- 0
- 0
I have a struct with array pointers to doubles. I want the pointers to point to an array of doubles and my question is how do I access the double in the array?
Originally posted by: BornStar18
structname.array[x]
I can't remember if C uses [] or () so modify accordingly. .
edit: forums messed up my post
Originally posted by: BornStar18
An array is a pointer automtically. I guess I'm not exactly sure what you're asking. If you define it:
struct{
doubles[100]
} somestruct;
somestruct bah;
you would access the first double number stored as "bah.doubles[0]".
Are you saying that its a (pointer to a (pointer to an array))?
So you have an array that points to an array then? I guess I've never really contemplated that before. Give me a minute while i think about it.Originally posted by: Spencer278
I have some thing like
struct MyStruct {
double* StructArray[100];
} foo;
foo.structArray[n] = someArray;
I need to be able to get a double out of someArray given foo
I'm not so sure your second suggestion will work but I see no reason why your first one wouldn't. I think that's what you should do. This is rather messy and I'm not even sure there's a way to do it.Originally posted by: RaynorWolfcastle
You might want to consider simplifying your data structure if that's possible in the context you're using it (by using a multidimentional array for example)
otherwise I'd guess you might be able to access it using the dereference operator... maybe (&(foo.structArray[n]))[k] I'm really not sure if that'll work, but give it a go.
Alright, yeah, you can't do that. Since an array variable is already a pointer, you're trying to make a pointer out of a pointer which is just no good. Double dimension your array and be done with it.Originally posted by: Spencer278
I have some thing like
struct MyStruct {
double* StructArray[100];
} foo;
foo.structArray[n] = someArray;
I think I'm doing something wrong on that line. I want that to mean an array of pointers but I don't think C is seeing it that way.
Originally posted by: Spencer278
I have some thing like
struct MyStruct {
double* StructArray[100];
} foo;
foo.structArray[n] = someArray;
I think I'm doing something wrong on that line. I want that to mean an array of pointers but I don't think C is seeing it that way.
