Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>The <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/scanf.html" rel="nofollow noreferrer"><code>scanf()</code></a> function removes whitespace automatically before trying to parse conversions other than characters. The character formats (primarily <code>%c</code>; also scan sets <code>%[…]</code> — and <code>%n</code>) are the exception; they don't remove whitespace.</p> <p>Use <code>" %c"</code> with a leading blank to skip optional white space. Do not use a trailing blank in a <code>scanf()</code> format string.</p> <p>Note that this still doesn't consume any trailing whitespace left in the input stream, not even to the end of a line, so beware of that if also using <a href="http://en.cppreference.com/w/c/io/getchar" rel="nofollow noreferrer"><code>getchar()</code></a> or <a href="http://en.cppreference.com/w/c/io/fgets" rel="nofollow noreferrer"><code>fgets()</code></a> on the same input stream. We're just getting scanf to skip over whitespace <em>before</em> conversions, like it does for <code>%d</code> and other non-character conversions.</p> <hr> <p>Note that non-whitespace "directives" (to use <a href="http://pubs.opengroup.org/onlinepubs/9699919799/functions/scanf.html" rel="nofollow noreferrer">POSIX scanf terminology</a>) other than conversions, like the literal text in <code>scanf("order = %d", &amp;order);</code> doesn't skip whitespace either. The literal <code>order</code> has to match the next character to be read.</p> <p>So you probably want <code>" order = %d"</code> there if you want to skip a newline from the previous line but still require a literal match on a fixed string, <a href="https://stackoverflow.com/questions/49923312/scanf-run-twice-instead-of-one-time-at-assembly-x86-64">like this question</a>.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload