Advertisement

Char

Started by July 16, 2002 02:01 PM
6 comments, last by Jonbca 22 years, 5 months ago
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.
strcat
Advertisement
will strcat work with a interger in the middle?
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]
I think something like this should work:

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]
file name 256 huh?
wierd....LOL!
Advertisement
Why not use std::string?
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=========================================*/

This topic is closed to new replies.

Advertisement