Jump to content
  • Advertisement

Archived

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

array sizing for file input

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

If you intended to correct an error in the post then please contact us.

Recommended Posts

Id like to thank everyone who has helped me figure things out. reading files in is messed up because there are so many ways to do it. I think I have a handle on it now. Now for my question: using VC++6. I read in my file and the first 2 numbers read in are the sizes I want my arrays to be. InputFile >> n1; InputFile >> n2; GLfloat array1[n1]; GLint array2[n2]; so I want to initialise the arrays to these sizes but I have to initialise them in the .h file (ie array1[10000])so I can access them in my vertex array function. any suggestions on setting this up?

Share this post


Link to post
Share on other sites
Advertisement
Get a towel and wipe up all that leaked memory!

    
InputFile >> n1;
InputFile >> n2;

GLfloat *Array1 = new GLfloat [ n1 ];
GLint *Array2 = new GLint [ n2 ];


when you're done :
  

// Make sure that Array1 and Array2 exist before trying to delete! (Or there will be trouble)

if (Array1) delete [] Array1;
if (Array2) delete [] Array2;



I hope that this helps!


Feel free to email me.

Edited by - Lord Karnus on September 19, 2001 12:54:22 AM

Share this post


Link to post
Share on other sites
thanks but Im still having errors:

InputFile>>nodes;
InputFile>>elements;
GLfloat *cylin = new GLfloat [nodes*3];
GLint *indi = new GLint [elements*3];

this seems to work. but after I finish using the
read in function and enter my display list
the pointers to cylin and indi change
so when I call
glDrawElements(GL_TRIANGLES, elements*3,GL_UNSIGNED_INT, indi);
code:
VC++6.0
void CMainFrame::reader()
{
// int k;
GLfloat u[3],v[3],n[3];
ifstream InputFile;
ifstream InputFile2;

InputFile.open("input.txt", ios::in , filebuf::openprot);
InputFile>>nodes;
InputFile>>elements;
GLfloat *cylin = new GLfloat [nodes*3];
GLint *indi = new GLint [ elements*3 ];



InputFile.close();
InputFile.open("test.txt", ios::in , filebuf::openprot);
for(int i = 0; (i < nodes*3) && !InputFile.eof(); ++i)
{
InputFile>>cylin;
}
InputFile.close();
InputFile2.open("elemout.txt", ios::in , filebuf::openprot);
for(i = 0; (i < elements*3 ) && !InputFile2.eof(); ++i)
{
InputFile2>>indi[i];
indi[i] = indi[i]-1;
}
InputFile2.close();
}

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
Also you may want to set the variables Array1 and Array2 to NULL
as when they are deleted you can still reference them

eg..
delete Array1
...//later on after deletion

GLint i = Array2[2];

would still be ok by the compilerand at run time but you would get garbage values. Where as if it was null the computer would complain.

Hope this helps

Share this post


Link to post
Share on other sites
From what I can make of your code, cylin and indi are local variables. They lose scope before you get to the display list (and thus are nonexistent).
  
// to put your code in nice white boxes like this one, pre- and postfix

// them with source and /source tag pairs (GameDev.Net tags are enclosed

// in square brackets: []). To just keep the spacing, put them in code

// and /code tag pairs

Share this post


Link to post
Share on other sites
   just testing out what you said   


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 this post


Link to post
Share on other sites
my reccomendation (for simplicity) is use apVector.

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 this post


Link to post
Share on other sites
my reccomendation (for simplicity) is use apVector.

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 this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!