The Dink Network

Reply to Re: sprintf is molesting

If you don't have an account, just leave the password field blank.
Username:
Password:
Subject:
Antispam: Enter Dink Smallwood's last name (surname) below.
Formatting: :) :( ;( :P ;) :D >( : :s :O evil cat blood
Bold font Italic font hyperlink Code tags
Message:
 
 
August 17th 2005, 01:45 AM
wizardb.gif
merlin
Peasant He/Him
 
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.