sprintf is molesting
Again with this thing.
sprintf(crap, "%d", spr[h].damage);
cr := &crap[0];
"crap" is type char[200],
"spr[h].damage" is int, and
"cr" is *char.
So, sprintf what does?
1) Moves the values directly, like if "damage" is FF00FF00, then "crap" will have [FF, 00, FF, 00].
2) Converts the value, like if "damage" is 000000FF (255), then "crap" will have [FF] (255).
It could be prudent if someone puts the description of that procedure, so I can stop molesting with this again.
sprintf(crap, "%d", spr[h].damage);
cr := &crap[0];
"crap" is type char[200],
"spr[h].damage" is int, and
"cr" is *char.
So, sprintf what does?
1) Moves the values directly, like if "damage" is FF00FF00, then "crap" will have [FF, 00, FF, 00].
2) Converts the value, like if "damage" is 000000FF (255), then "crap" will have [FF] (255).
It could be prudent if someone puts the description of that procedure, so I can stop molesting with this again.
Neither.
If the value of damage is '114', then the value of crap is the array of characters '1', '1', '4', '\0'. It basically converts the integer value into a string.
I'm sure Merlin can come up with a better explanation.
If the value of damage is '114', then the value of crap is the array of characters '1', '1', '4', '\0'. It basically converts the integer value into a string.
I'm sure Merlin can come up with a better explanation.
The purpose of sprintf is to write formatted output to a buffer. That buffer, in this case, is crap. The next argument to sprintf determines the type of the next argument...the most common are %s, string, and %d, integer. Since spr[h].damage is of type int, %d should be used.
The function essentially does exactly what printf does, except captures the STDIO output and puts it into the buffer. So, sprintf is converting the value of spr[h].damage to a string and storing it in crap. Redink's example is correct.
The function essentially does exactly what printf does, except captures the STDIO output and puts it into the buffer. So, sprintf is converting the value of spr[h].damage to a string and storing it in crap. Redink's example is correct.