Archived

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

Jonbca

Char

Recommended Posts

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.

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites
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]

Share this post


Link to post
Share on other sites