Char
I''m wortk throught the NeHE''s openGL tutorials right now and I''m trying to settup something so I can go like this
int index;
for (index=0;index<=6;index++)
{
LoadBmp("smiles"+index+".bmp")
...
}
so that I can use a group of bmp named smiles1.bmp smiles2.bmp ...
but I don''t know how to do this using the char variable type. Any help would be great.
Declare a char array, like char filename[32];
In your loop:
sprintf(filename, "smiles%i.bmp", index);
LoadBmp(filename);
edit:using strcat would require you to also use either atoi or itoa (forgot which one), sprintf would be easier
[edited by - atcdevil on July 16, 2002 3:09:33 PM]
In your loop:
sprintf(filename, "smiles%i.bmp", index);
LoadBmp(filename);
edit:using strcat would require you to also use either atoi or itoa (forgot which one), sprintf would be easier
[edited by - atcdevil on July 16, 2002 3:09:33 PM]
I think something like this should work:
I tried it using strcat, but I can't remember how to convert an integer to a string (I remember converting a string to an integer, but not the other way around).
Matt
P.S. Be sure to look up sprintf() in your documentation. Don't just use the code--understand it.
Huh...someone else already posted the answer. Nuts.
[edited by - CoderForChrist on July 16, 2002 3:19:30 PM]
for (int i=0; i<=6; i++) { char filename[256]; sprintf(filename, "smiles%i.bmp", i); LoadBmp(filename); ...}
I tried it using strcat, but I can't remember how to convert an integer to a string (I remember converting a string to an integer, but not the other way around).
Matt
P.S. Be sure to look up sprintf() in your documentation. Don't just use the code--understand it.
Huh...someone else already posted the answer. Nuts.
[edited by - CoderForChrist on July 16, 2002 3:19:30 PM]
Yes, std::string would be much simpler.
/*=========================================*/
/* Chem0sh */
/* Lead Software Engineer & Tech Support */
/* http://www.eFaces.biz */
/*=========================================*/
/*=========================================*/
/* Chem0sh */
/* Lead Software Engineer & Tech Support */
/* http://www.eFaces.biz */
/*=========================================*/
/*=========================================// Chem0sh// Lead Software Engineer & Tech Support// http://www.eFaces.biz=========================================*/
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement