Re: Loop Does'nt Work, Hard code does
From: Daniel T. (postmaster_at_eathlink.net)
Date: 08/31/04
- Next message: William Payne: "Re: move element in vector"
- Previous message: Daniel T.: "Re: Is it safe for me to delete one of those two functions with the same name 'getTime'"
- In reply to: Nick L: "Loop Does'nt Work, Hard code does"
- Next in thread: red floyd: "Re: Loop Does'nt Work, Hard code does"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 31 Aug 2004 11:28:22 GMT
In article <86VYc.263646$eM2.249913@attbi_s51>,
"Nick L" <Fearnot003@mchsi.com> wrote:
> I'm working on a function which creates a pointers to an array of unsigned
> ints based off a number read from a file. I then continue to read file names
> from the file, convert the name to a char* and use it to load an texture
> from some outside functions. My problem lies in the "for loop", the Code
> goes as follows.
>
> //I create the array of pointers, I'm using 2 just for the sake of an
> example
> MapTextures = new unsigned int[2];
>
> //Start up a for loop
> for(int I = 0; I < 2; I++)
> { //I then read the filename from the file.
> LevelStream >> Cmd;
> //Convert the string I read to a char*
> Name = strdup (Cmd.c_str());
> //Use the filename to load the coorisponding image into the first
> element on the array
> MapTextures[I] = LoadTextureWithAlpha(Name);
> }
Your code looks like it leaks memory. Why are you using strdup?
const size_t limit = 2;
unsigned* MapTextures = new unsigned[limit];
for ( unsigned i = 0; i < limit; ++i ) {
string Cmd;
LevelStream >> Cmd;
MapTextures[i] = LoadTextureWithAlpha(Cmd.c_str());
}
> This is the way I'd like to do it, but for some reason it does'nt work and
> for the life of me I can't figure out why. When the code executes it will
> read both file names and convert them just fine, but it will only load one
> texture.
When you say it will only load one texture, do you mean that both
MapTextures elements contain the same value?
- Next message: William Payne: "Re: move element in vector"
- Previous message: Daniel T.: "Re: Is it safe for me to delete one of those two functions with the same name 'getTime'"
- In reply to: Nick L: "Loop Does'nt Work, Hard code does"
- Next in thread: red floyd: "Re: Loop Does'nt Work, Hard code does"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|