sprintfk
Prev | Orchestra Opcodes and Operators | Next

## sprintfk

sprintfk — printf-style formatted output to a string variable at k-rate.

## Description

sprintfk writes printf-style formatted output to a string variable, similarly to the C function sprintf(). sprintfk runs both at initialization and performance time.

## Syntax

    Sdst sprintfk Sfmt, xarg1[, xarg2[, ... ]]

## Initialization

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. sprintfk also allows k-rate number arguments, but these should still be valid at init time as well (unless sprintfk is skipped with igoto). Integer formats like %d round the input values to the nearest integer.

## Performance

Sdst -- output string variable

## Examples

Here is an example of the sprintfk opcode. It uses the file sprintfk.csd.

Example 480. Example of the sprintfk 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
    ; Audio out   Audio in
    -odac           -iadc    ;;;RT audio I/O
    ; For Non-realtime ouput leave only the line below:
    ; -o sprintfk.wav -W ;;; for file output any platform
    </CsOptions>
    <CsInstruments>

      sr	    =  48000
      ksmps	    =  16
      nchnls    =  2
      0dbfs	    =  1

    ; Example by Jonathan Murphy 2007

        instr 1

      S1	    =  "1"
      S2	    =  " + 1"
      ktrig	    init      0
      kval	    init      2
    if (ktrig == 1) then
      S1	    strcatk   S1, S2
      kval	    =  kval + 1
    endif
      String    sprintfk  "%s = %d", S1, kval
    	    puts      String, kval
      ktrig	    metro     1

        endin

    </CsInstruments>
    <CsScore>
    i1 0 10
    e
    </CsScore>
    </CsoundSynthesizer>

## See also

sprintf, puts, strcatk

## Credits

Author: Istvan Varga
2005
Example by Jonathan Murphy

Prev | Up | Next
sprintf | Home | sqrt