GinDiamond wrote:
Can you guys take a look at my status bar function, it seems clunky, is there a better way to construct a status bar? I think it won't work if health is below a 2 digit number.
Code:
void printStat()
{
itoa(hp, int_str, 10);
strcpy(status_str, "HP: ");
strcpy(status_str + 4, int_str);
strcpy(status_str + 4 + 2, " \t");
puts(status_str);
strcpy(status_str, "Gold: ");
itoa(gold, int_str, 10);
strcpy(status_str + 4 + 2, int_str);
puts(status_str);
}
Why strcpy constant strings when you can just puts() them directly as you go along?
Code:
void printStat()
{
itoa(hp, int_str, 10);
puts("HP: ");
puts(int_str);
puts(" \tGold: ");
itoa(gold, int_str, 10);
puts(int_str);
}
Also, I haven't seen anyone write new C code using this ancient format (original K&R C) before - although I have seen plenty of very old code written this way:
Code:
void combat(i)
uint8_t i;
{
//
}
The cool C kids these days use the ANSI/ISO format, which looks like this:
Code:
void combat(uint8_t i)
{
//
}
The old format is still considered valid C, so no need to change it. Indeed, I wondered if you were using it for a "retro" feel to your code.