|
textprintf_ex format modifiers |
xmltorrent
Member #7,673
August 2006
|
I'm having trouble remembering how to handle the %s format modifier of textprintf_ex. Basically, I just want to display information about the data structure on the screen so I know what I'm dealing with. First off, here's the data structure I have. It contains four other data structures as its members. typedef struct PLAYER{ char *name; WEAPON *current_weapon; ARMOR *current_armor; ACCESSORY *current_accessory; SPRITE *sprite; }PLAYER; Now here's the function that initializes an instance (not correct terminology but it's how I know it as) of the PLAYER structure:
Now here's the function that displays the information on the player. I was just getting here doing one line at a time for errors so that's why it's as small as it is: void print_player_information(PLAYER *player){ acquire_bitmap(buffer); textprintf_ex(buffer, font, 0, 0, WHITE, -1, "Player Information"); textprintf_ex(buffer, font, 0, 10, WHITE, -1, "Name: %s", &player->name); release_bitmap(buffer); } The code doesn't generate errors when compiled... and the program even runs. But instead of the name, I get a bunch of random characters. How do I fix this? |
Matthew Dalrymple
Member #7,922
October 2006
|
=-----===-----===-----= |
xmltorrent
Member #7,673
August 2006
|
No because the %s modifier looks for an address. |
Kitty Cat
Member #2,815
October 2002
|
char* is already an address. You're passing an address to an address. Beyond that, you're allocating a local 'player' pointer, but never giving that pointer back for the rest of the program. -- |
xmltorrent
Member #7,673
August 2006
|
Suggestion as to what I should do? |
Matthew Leverton
Supreme Loser
January 1999
|
PLAYER *init_player(void){ // ... return player; } player = init_player();
|
Kris Asick
Member #1,424
July 2001
|
Remove the & symbol from your textprintf_ex() statement and you'll be fine. I exclusively use the variety of printf statements available in Allegro and C/C++. I don't actually know how to use cout or Allegro's textout functions. --- Kris Asick (Gemini) --- Kris Asick (Gemini) |
|