<?xml version="1.0" encoding="UTF-8" standalone="no"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>sprintfk</title> <link rel="stylesheet" type="text/css" href="csound.css" /> <meta name="generator" content="DocBook XSL Stylesheets V1.76.1" /> <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" /> <link rel="up" href="OpcodesTop.html" title="Orchestra Opcodes and Operators" /> <link rel="prev" href="sprintf.html" title="sprintf" /> <link rel="next" href="spsend.html" title="spsend" /> </head> <body> <div class="navheader"> <table width="100%" summary="Navigation header"> <tr> <th colspan="3" align="center">sprintfk</th> </tr> <tr> <td width="20%" align="left"><a accesskey="p" href="sprintf.html">Prev</a> </td> <th width="60%" align="center">Orchestra Opcodes and Operators</th> <td width="20%" align="right"> <a accesskey="n" href="spsend.html">Next</a></td> </tr> </table> <hr /> </div> <div class="refentry" title="sprintfk"> <a id="sprintfk"></a> <div class="titlepage"></div> <a id="Indexsprintfk" class="indexterm"></a> <div class="refnamediv"> <h2> <span class="refentrytitle">sprintfk</span> </h2> <p>sprintfk — printf-style formatted output to a string variable at k-rate. </p> </div> <div class="refsect1" title="Description"> <a id="idp45142504"></a> <h2>Description</h2> <p> <span class="emphasis"><em>sprintfk</em></span> writes printf-style formatted output to a string variable, similarly to the C function sprintf(). <span class="emphasis"><em>sprintfk</em></span> runs both at initialization and performance time. </p> </div> <div class="refsect1" title="Syntax"> <a id="idp45153048"></a> <h2>Syntax</h2> <pre class="synopsis">Sdst <span class="command"><strong>sprintfk</strong></span> Sfmt, xarg1[, xarg2[, ... ]]</pre> </div> <div class="refsect1" title="Initialization"> <a id="idp45154104"></a> <h2>Initialization</h2> <p> <span class="emphasis"><em>Sfmt</em></span> -- 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: </p> <div class="itemizedlist"> <ul class="itemizedlist" type="disc"> <li class="listitem"> <p>d, i, o, u, x, X, e, E, f, F, g, G, c, s</p> </li> </ul> </div> <p> </p> <p> <span class="emphasis"><em>xarg1, xarg2, ...</em></span> -- 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. </p> </div> <div class="refsect1" title="Performance"> <a id="idp45156464"></a> <h2>Performance</h2> <p> <span class="emphasis"><em>Sdst</em></span> -- output string variable </p> </div> <div class="refsect1" title="Examples"> <a id="idp45157304"></a> <h2>Examples</h2> <p> Here is an example of the sprintfk opcode. It uses the file <a class="ulink" href="examples/sprintfk.csd" target="_top"><em class="citetitle">sprintfk.csd</em></a>. </p> <div class="example"> <a id="idp45158288"></a> <p class="title"> <strong>Example 791. Example of the sprintfk opcode.</strong> </p> <div class="example-contents"> <p>See the sections <a class="link" href="UsingRealTime.html" title="Real-Time Audio"><em class="citetitle">Real-time Audio</em></a> and <a class="link" href="CommandFlags.html" title="Csound command line"><em class="citetitle">Command Line Flags</em></a> for more information on using command line flags.</p> <pre class="programlisting"> <span class="csdtag"><CsoundSynthesizer></span> <span class="csdtag"><CsOptions></span> <span class="comment">; Select audio/midi flags here according to platform</span> <span class="comment">; Audio out Audio in</span> -odac -iadc <span class="comment">;;;RT audio I/O</span> <span class="comment">; For Non-realtime ouput leave only the line below:</span> <span class="comment">; -o sprintfk.wav -W ;;; for file output any platform</span> <span class="csdtag"></CsOptions></span> <span class="csdtag"><CsInstruments></span> <span class="ohdr">sr</span> <span class="op">=</span> 48000 <span class="ohdr">ksmps</span> <span class="op">=</span> 16 <span class="ohdr">nchnls</span> <span class="op">=</span> 2 <span class="ohdr">0dbfs</span> <span class="op">=</span> 1 <span class="comment">; Example by Jonathan Murphy 2007</span> <span class="oblock">instr</span> 1 S1 <span class="op">=</span> "1" S2 <span class="op">=</span> " <span class="op">+</span> 1" ktrig <span class="opc">init</span> 0 kval <span class="opc">init</span> 2 <span class="octrl">if</span> (ktrig <span class="op">==</span> 1) then S1 <span class="opc">strcatk</span> S1, S2 kval <span class="op">=</span> kval <span class="op">+</span> 1 <span class="octrl">endif</span> String <span class="opc">sprintfk</span> "<span class="op">%</span>s <span class="op">=</span> <span class="op">%</span>d", S1, kval <span class="opc">puts</span> String, kval ktrig <span class="opc">metro</span> 1 <span class="oblock">endin</span> <span class="csdtag"></CsInstruments></span> <span class="csdtag"><CsScore></span> <span class="stamnt">i</span>1 0 10 <span class="stamnt">e</span> <span class="csdtag"></CsScore></span> <span class="csdtag"></CsoundSynthesizer></span> </pre> </div> </div> <p><br class="example-break" /> Its output should include lines like this: </p> <pre class="screen"> 1 + 1 = 2 1 + 1 + 1 = 3 1 + 1 + 1 + 1 = 4 1 + 1 + 1 + 1 + 1 = 5 1 + 1 + 1 + 1 + 1 + 1 = 6 1 + 1 + 1 + 1 + 1 + 1 + 1 = 7 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 = 8 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 = 9 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 = 10 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 = 11 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 + 1 = 12</pre> <p> </p> </div> <div class="refsect1" title="See also"> <a id="idp45190296"></a> <h2>See also</h2> <p> <a class="link" href="sprintf.html" title="sprintf"><em class="citetitle">sprintf</em></a>, <a class="link" href="puts.html" title="puts"><em class="citetitle">puts</em></a>, <a class="link" href="strcatk.html" title="strcatk"><em class="citetitle">strcatk</em></a> </p> </div> <div class="refsect1" title="Credits"> <a id="idp45192296"></a> <h2>Credits</h2> <p> </p> <table border="0" summary="Simple list" class="simplelist"> <tr> <td>Author: Istvan Varga</td> </tr> <tr> <td>2005</td> </tr> <tr> <td>Example by Jonathan Murphy</td> </tr> </table> <p> </p> </div> </div> <div class="navfooter"> <hr /> <table width="100%" summary="Navigation footer"> <tr> <td width="40%" align="left"><a accesskey="p" href="sprintf.html">Prev</a> </td> <td width="20%" align="center"> <a accesskey="u" href="OpcodesTop.html">Up</a> </td> <td width="40%" align="right"> <a accesskey="n" href="spsend.html">Next</a></td> </tr> <tr> <td width="40%" align="left" valign="top">sprintf </td> <td width="20%" align="center"> <a accesskey="h" href="index.html">Home</a> </td> <td width="40%" align="right" valign="top"> spsend</td> </tr> </table> </div> </body> </html>