#### Archived

This topic is now archived and is closed to further replies.

# HELP! Matrix/Array Problems

This topic is 6068 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey, I load information from a file, the format looks like this.
  NumberOfPairs PairPart1 PairPart2 PairPart1 PairPart2 PairPart1 PairPart2 PairPart1 PairPart2 PairPart1 PairPart2 . . . 
What I need to do is to create a matrix like so.
  float Data[NumberOfPairs][2]; 
But I find this very hard to do. I have tried to do this using dynamic memory allocation (ie: float *x=new float[3]), but I can''t figure out how to do this with a matrix, only an array. Any help is greatly appreciated. Alex Broadwin A-Tronic Software & Design ----- "if you fail in life, you were destined to fail. If you suceed in life, call me." "The answer is out there." "Please help, I''m using Windows!"

##### Share on other sites
This is one of the cheats you can use with dynamic allocation when the non-first indices are constant:
  float *(Data[2]);Data = new Data[Number][2];

I''ve never had to do this, but as far as I know it should work. Otherwise, for clarity, do this:
  struct Pair { float A, B;};Pair *Data;Data = new Pair[Number];

[Resist Windows XP''s Invasive Production Activation Technology!]

##### Share on other sites
Thank you SOOO much! I''ll have to do the first one, since it MUST be a matrix of floats in the format of a matrix of floats. The function I pass it to requires it, it''s for opengl vertex arrays. Thank you again!

A-Tronic Software & Design
-----
"if you fail in life, you were destined to fail. If you suceed in life, call me."

##### Share on other sites
#include

int main()
{
int (*x)[3]=new int[2][3];

x[0][0]=1;x[0][1]=2;x[0][2]=3;
x[1][0]=4;x[1][1]=5;x[1][2]=6;
printf("\n%d %d %d", x[0][0], x[0][1], x[0][2]);
printf("\n%d %d %d", x[1][0], x[1][1], x[1][2]);

system("PAUSE");
return 0;
}

##### Share on other sites
Null And Void,
Problem. I get the error "no an lvalue" when I try to compile. It thinks that your code:
  float *(Data[2]);Data = new Data[Number][2];

should be this:
  float *(Data[2]);Data[0] = new Data[Number][2];

or something of the like. By the way did you mean Data=new float[number][2]? Anyway, any ideas?

A-Tronic Software & Design
-----
"if you fail in life, you were destined to fail. If you suceed in life, call me."

##### Share on other sites
  #include #include //void call(float f[][2]){}//void main(void){ int x = rand()&0xff; call(new float [x][2]); float (*m)[2] = new float [x][2];}

##### Share on other sites
quote:
Original post by ATronic
By the way did you mean Data=new float[number][2]?

Yes, I did. I think it goes like this though, to correct myself:
  float (*Data)[2];Data = new float[Number][2];

It is kind of unintelligible, I know, that's why I had to look it up .

[Resist Windows XP's Invasive Production Activation Technology!]

Edited by - Null and Void on November 9, 2001 8:10:57 PM

• 18
• 11
• 16
• 9
• 50
• ### Forum Statistics

• Total Topics
631396
• Total Posts
2999783
×