sprintf — printf-style formatted output to a string variable.
sprintf write printf-style formatted output to a string variable, similarly to the C function sprintf(). sprintf runs at i-time only.
Sfmt -- format string, has the same format as in printf() and other similar C functions, except length modifiers (l, ll, h, etc.) are not supported. The following conversion specifiers are allowed:
d, i, o, u, x, X, e, E, f, F, g, G, c, s
xarg1, xarg2, ... -- input arguments (max. 30) for format, should be i-rate for all conversion specifiers except %s, which requires a string argument. Integer formats like %d round the input values to the nearest integer.
Here is an example of the sprintf opcode. It uses the file sprintf.csd.
Example 999. Example of the sprintf opcode.
See the sections Real-time Audio and Command Line Flags for more information on using command line flags.
<CsoundSynthesizer> <CsOptions> ; Select audio/midi flags here according to platform -odac ;;;realtime audio out ;-iadc ;;;uncomment -iadc if realtime audio input is needed too ; For Non-realtime ouput leave only the line below: ; -o sprintf.wav -W ;;; for file output any platform </CsOptions> <CsInstruments> sr = 44100 ksmps = 32 nchnls = 2 0dbfs = 1 ;the file "impuls20.aiff" can be found in /manual/examples instr 1 ifn = 20 Sname sprintf "impuls%02d.aiff", ifn Smsg sprintf "The file name is: '%s'", Sname puts Smsg, 1 asig soundin Sname outs asig, asig endin </CsInstruments> <CsScore> i 1 0 1 e </CsScore> </CsoundSynthesizer>
Its output should include lines like this:
The file name is: 'impuls20.aiff' soundin: opened 'impuls20.aiff'