Advertisement

External array with variable size?

Started by March 01, 2003 01:37 PM
3 comments, last by Lode 21 years, 8 months ago
How can I make an array that's external, and can change size while the program runs (in C)? It's for a video buffer for a program with changing screen resolutions. It doesn't have to be completely external, just in one c file. Thanks. PS I guess this question is pretty beginner so I ask it here. [edited by - Lode on March 1, 2003 2:39:29 PM]
"External"?
Advertisement
quote: Original post by Anonymous Poster
"External"?


That was the most useless reply I could imagine.
quote: Original post by Lode
Original post by Anonymous Poster
"External"?


That was the most useless reply I could imagine.

If it didn''t accur to you,
"External"? == Elaborate on that, because that doesn''t seem to be the correct term.
no, it wasnt, he was asking because your post contained something that doesn''t fit in. I still dont know what you mean for sure, but I think I have a slight idea.


What you want is a global, and a function to resize it. Because of this, it needs to be a pointer. here is an example:

  char *vbuf;int x, y; // old size of the vbuf.bool Resize( int NewX, int NewY ){   if( NewX < x || NewY < y )      return false;   char NewVbuf;   NewVbuf = new char[NewX * NewY];   for( int i = 0; i < x; i++ )   {      for( int n = 0; n < y; n++ )         NewVbuf = vbuf[n*y+i];   }   delete vbuf;   vbuf = NewVbuf;   x = NewX;   y = NewY;   return true;}  


pretty much. could use some extra things, like making the new buf smaller than the old one, but...

// Eric

This topic is closed to new replies.

Advertisement