<html lang="en"> <head> <title>String Input Conversions - GNU Octave</title> <meta http-equiv="Content-Type" content="text/html"> <meta name="description" content="GNU Octave"> <meta name="generator" content="makeinfo 4.13"> <link title="Top" rel="start" href="index.html#Top"> <link rel="up" href="C_002dStyle-I_002fO-Functions.html#C_002dStyle-I_002fO-Functions" title="C-Style I/O Functions"> <link rel="prev" href="Numeric-Input-Conversions.html#Numeric-Input-Conversions" title="Numeric Input Conversions"> <link rel="next" href="Binary-I_002fO.html#Binary-I_002fO" title="Binary I/O"> <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage"> <meta http-equiv="Content-Style-Type" content="text/css"> <style type="text/css"><!-- pre.display { font-family:inherit } pre.format { font-family:inherit } pre.smalldisplay { font-family:inherit; font-size:smaller } pre.smallformat { font-family:inherit; font-size:smaller } pre.smallexample { font-size:smaller } pre.smalllisp { font-size:smaller } span.sc { font-variant:small-caps } span.roman { font-family:serif; font-weight:normal; } span.sansserif { font-family:sans-serif; font-weight:normal; } --></style> </head> <body> <div class="node"> <a name="String-Input-Conversions"></a> <p> Next: <a rel="next" accesskey="n" href="Binary-I_002fO.html#Binary-I_002fO">Binary I/O</a>, Previous: <a rel="previous" accesskey="p" href="Numeric-Input-Conversions.html#Numeric-Input-Conversions">Numeric Input Conversions</a>, Up: <a rel="up" accesskey="u" href="C_002dStyle-I_002fO-Functions.html#C_002dStyle-I_002fO-Functions">C-Style I/O Functions</a> <hr> </div> <h4 class="subsection">14.2.15 String Input Conversions</h4> <p>This section describes the <code>scanf</code> input conversions for reading string and character values: ‘<samp><span class="samp">%s</span></samp>’ and ‘<samp><span class="samp">%c</span></samp>’. <p>The ‘<samp><span class="samp">%c</span></samp>’ conversion is the simplest: it matches a fixed number of characters, always. The maximum field with says how many characters to read; if you don't specify the maximum, the default is 1. This conversion does not skip over initial whitespace characters. It reads precisely the next <var>n</var> characters, and fails if it cannot get that many. <p>The ‘<samp><span class="samp">%s</span></samp>’ conversion matches a string of non-whitespace characters. It skips and discards initial whitespace, but stops when it encounters more whitespace after having read something. <p>For example, reading the input: <pre class="example"> hello, world </pre> <p class="noindent">with the conversion ‘<samp><span class="samp">%10c</span></samp>’ produces <code>" hello, wo"</code>, but reading the same input with the conversion ‘<samp><span class="samp">%10s</span></samp>’ produces <code>"hello,"</code>. </body></html>