Conversions
Following the <span class="Cm">%</span> character or <span class="Cm">%n </span> sequence introducing a conversion there may be a number of <span class="Em">flag</span> characters, as follows:
<table cellspacing="0" class="refpage" style="margin-left:25px">
<tr>
<td valign="top" nowrap>
<span class="Cm">*</span>
</td>
<td valign="top">
Suppresses assignment. The conversion that follows occurs as usual, but no pointer is used; the result of the conversion is simply discarded.
</td>
</tr>
<tr>
<td valign="top" nowrap>
<span class="Cm">hh</span>
</td>
<td valign="top">
Indicates that the conversion will be one of <span class="Cm">dioux</span> or <span class="Cm">n</span> and the next pointer is a pointer to a <span class="Vt">char</span> (rather than <span class="Vt">int</span>).
</td>
</tr>
<tr>
<td valign="top" nowrap>
<span class="Cm">h</span>
</td>
<td valign="top">
Indicates that the conversion will be one of <span class="Cm">dioux</span> or <span class="Cm">n</span> and the next pointer is a pointer to a <span class="Vt">short int</span> (rather than <span class="Vt">int</span>).
</td>
</tr>
<tr>
<td valign="top" nowrap>
<span class="Cm">l</span> (ell)
</td>
<td valign="top">
Indicates that the conversion will be one of <span class="Cm">dioux</span> or <span class="Cm">n</span> and the next pointer is a pointer to a <span class="Vt">long int</span> (rather than <span class="Vt">int</span>), that the conversion will be one of <span class="Cm">a</span>, <span class="Cm">e</span>, <span class="Cm">f</span>, or <span class="Cm">g</span> and the next pointer is a pointer to <span class="Vt">double</span> (rather than <span class="Vt">float</span>), or that the conversion will be one of <span class="Cm">c</span>, <span class="Cm">s</span> or <span class="Cm">[</span> and the next pointer is a pointer to an array of <span class="Vt">wchar_t</span> (rather than <span class="Vt">char</span>).
</td>
</tr>
<tr>
<td valign="top" nowrap>
<span class="Cm">ll</span> (ell ell)
</td>
<td valign="top">
Indicates that the conversion will be one of <span class="Cm">dioux</span> or <span class="Cm">n</span> and the next pointer is a pointer to a <span class="Vt">long long int</span> (rather than <span class="Vt">int</span>).
</td>
</tr>
<tr>
<td valign="top" nowrap>
<span class="Cm">L</span>
</td>
<td valign="top">
Indicates that the conversion will be one of <span class="Cm">a</span>, <span class="Cm">e</span>, <span class="Cm">f</span>, or <span class="Cm">g</span> and the next pointer is a pointer to <span class="Vt">long double</span>.
</td>
</tr>
<tr>
<td valign="top" nowrap>
<span class="Cm">j</span>
</td>
<td valign="top">
Indicates that the conversion will be one of <span class="Cm">dioux</span> or <span class="Cm">n</span> and the next pointer is a pointer to a <span class="Vt">intmax_t</span> (rather than <span class="Vt">int</span>).
</td>
</tr>
<tr>
<td valign="top" nowrap>
<span class="Cm">t</span>
</td>
<td valign="top">
Indicates that the conversion will be one of <span class="Cm">dioux</span> or <span class="Cm">n</span> and the next pointer is a pointer to a <span class="Vt">ptrdiff_t</span> (rather than <span class="Vt">int</span>).
</td>
</tr>
<tr>
<td valign="top" nowrap>
<span class="Cm">z</span>
</td>
<td valign="top">
Indicates that the conversion will be one of <span class="Cm">dioux</span> or <span class="Cm">n</span> and the next pointer is a pointer to a <span class="Vt">size_t</span> (rather than <span class="Vt">int</span>).
</td>
</tr>
<tr>
<td valign="top" nowrap>
<span class="Cm">q</span>
</td>
<td valign="top">
(deprecated.) Indicates that the conversion will be one of <span class="Cm">dioux</span> or <span class="Cm">n</span> and the next pointer is a pointer to a <span class="Vt">long long int</span> (rather than <span class="Vt">int</span>).
</td>
</tr>
</table>
\n
\n
In addition to these flags, there may be an optional maximum field width, expressed as a decimal integer, between the <span class="Cm">%</span> and the conversion. If no width is given, a default of "<span class="Dq">infinity</span>" is used (with one exception, below); otherwise at most this many bytes are scanned in processing the conversion. In the case of the <span class="Cm">lc</span>, <span class="Cm">ls</span> and <span class="Cm">l[</span> conversions, the field width specifies the maximum number of multibyte characters that will be scanned. Before conversion begins, most conversions skip white space; this white space is not counted against the field width.
The following conversions are available:
<table cellspacing="0" class="refpage" style="margin-left:25px">
<tr>
<td valign="top" nowrap>
<span class="Cm">%</span>
</td>
<td valign="top">
Matches a literal '<span class="Qlq">%</span>'. That is, "<span class="Dq"><span class="Li">%%</span></span>" in the format string matches a single input '<span class="Qlq">%</span>' character. No conversion is done, and assignment does not occur.
</td>
</tr>
<tr>
<td valign="top" nowrap>
<span class="Cm">d</span>
</td>
<td valign="top">
Matches an optionally signed decimal integer; the next pointer must be a pointer to <span class="Vt">int</span>.
</td>
</tr>
<tr>
<td valign="top" nowrap>
<span class="Cm">i</span>
</td>
<td valign="top">
Matches an optionally signed integer; the next pointer must be a pointer to <span class="Vt">int</span>. The integer is read in base 16 if it begins with '<span class="Qlq">0x</span>' or '<span class="Qlq">0X</span>', in base 8 if it begins with '<span class="Qlq">0</span>', and in base 10 otherwise. Only characters that correspond to the base are used.
</td>
</tr>
<tr>
<td valign="top" nowrap>
<span class="Cm">o</span>
</td>
<td valign="top">
Matches an octal integer; the next pointer must be a pointer to <span class="Vt">unsigned int</span>.
</td>
</tr>
<tr>
<td valign="top" nowrap>
<span class="Cm">u</span>
</td>
<td valign="top">
Matches an optionally signed decimal integer; the next pointer must be a pointer to <span class="Vt">unsigned int</span>.
</td>
</tr>
<tr>
<td valign="top" nowrap>
<span class="Cm">x</span>, <span class="Cm">X</span>
</td>
<td valign="top">
Matches an optionally signed hexadecimal integer; the next pointer must be a pointer to <span class="Vt">unsigned int</span>.
</td>
</tr>
<tr>
<td valign="top" nowrap>
<span class="Cm">a</span>, <span class="Cm">A</span>, <span class="Cm">e</span>, <span class="Cm">E</span>, <span class="Cm">f</span>, <span class="Cm">F</span>, <span class="Cm">g</span>, <span class="Cm">G</span>
</td>
<td valign="top">
Matches a floating-point number in the style of
strtod. The next pointer must be a pointer to <span class="Vt">float</span> (unless <span class="Cm">l</span> or <span class="Cm">L</span> is specified.)
</td>
</tr>
<tr>
<td valign="top" nowrap>
<span class="Cm">s</span>
</td>
<td valign="top">
Matches a sequence of non-white-space characters; the next pointer must be a pointer to <span class="Vt">char</span>, and the array must be large enough to accept all the sequence and the terminating <span class="Dv">NUL</span> character. The input string stops at white space or at the maximum field width, whichever occurs first. \n
\n
If an <span class="Cm">l</span> qualifier is present, the next pointer must be a pointer to <span class="Vt">wchar_t</span>, into which the input will be placed after conversion by
mbrtowc.
</td>
</tr>
<tr>
<td valign="top" nowrap>
<span class="Cm">S</span>
</td>
<td valign="top">
The same as <span class="Cm">ls</span>.
</td>
</tr>
<tr>
<td valign="top" nowrap>
<span class="Cm">c</span>
</td>
<td valign="top">
Matches a sequence of <span class="Em">width</span> count characters (default 1); the next pointer must be a pointer to <span class="Vt">char</span>, and there must be enough room for all the characters (no terminating <span class="Dv">NUL</span> is added). The usual skip of leading white space is suppressed. To skip white space first, use an explicit space in the format. \n
\n
If an <span class="Cm">l</span> qualifier is present, the next pointer must be a pointer to <span class="Vt">wchar_t</span>, into which the input will be placed after conversion by
mbrtowc.
</td>
</tr>
<tr>
<td valign="top" nowrap>
<span class="Cm">C</span>
</td>
<td valign="top">
The same as <span class="Cm">lc</span>.
</td>
</tr>
<tr>
<td valign="top" nowrap>
<span class="Cm">[</span>
</td>
<td valign="top">
Matches a nonempty sequence of characters from the specified set of accepted characters; the next pointer must be a pointer to <span class="Vt">char</span>, and there must be enough room for all the characters in the string, plus a terminating <span class="Dv">NUL</span> character. The usual skip of leading white space is suppressed. The string is to be made up of characters in (or not in) a particular set; the set is defined by the characters between the open bracket <span class="Cm">[</span> character and a close bracket <span class="Cm">]</span> character. The set <span class="Em">excludes</span> those characters if the first character after the open bracket is a circumflex <span class="Cm">^</span>. To include a close bracket in the set, make it the first character after the open bracket or the circumflex; any other position will end the set. The hyphen character <span class="Cm">-</span> is also special; when placed between two other characters, it adds all intervening characters to the set. To include a hyphen, make it the last character before the final close bracket. For instance, '<span class="Qlq">[^]0-9-]</span>' means the set "<span class="Dq">everything except close bracket, zero through nine, and hyphen</span>". The string ends with the appearance of a character not in the (or, with a circumflex, in) set or when the field width runs out.
If an <span class="Cm">l</span> qualifier is present, the next pointer must be a pointer to <span class="Vt">wchar_t</span>, into which the input will be placed after conversion by
mbrtowc.
</td>
</tr>
<tr>
<td valign="top" nowrap>
<span class="Cm">p</span>
</td>
<td valign="top">
Matches a pointer value (as printed by '<span class="Qlq">%p</span>' in
printf); the next pointer must be a pointer to <span class="Vt">void</span>.
</td>
</tr>
<tr>
<td valign="top" nowrap>
<span class="Cm">n</span>
</td>
<td valign="top">
Nothing is expected; instead, the number of characters consumed thus far from the input is stored through the next pointer, which must be a pointer to <span class="Vt">int</span>. This is <span class="Em">not</span> a conversion, although it can be suppressed with the <span class="Cm">*</span> flag.
</td>
</tr>
</table>
The decimal point character is defined in the program's locale (category <span class="Dv">LC_NUMERIC</span>).
For backwards compatibility, a "<span class="Dq">conversion</span>" of '<span class="Qlq">%\0</span>' causes an immediate return of <span class="Dv">EOF</span>.