Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>*[Note: If you are going to use Objective-C you might wish to use input conversion methods from Cocoa rather than mix Cocoa (<code>NSLog</code>) and stdio (<code>scanf</code>). But that doesn't answer your question...]</p> <p>When parsing integers, floats and even strings <code>scanf</code> skips whitespace - e.g. spaces, tabs, <em>end of line</em>, etc. - and every input line ends with at least an end of line (which may be a carriage return, line feed, or both depending on the system). This means that after reading your first integer there is still, at least, an end of line in the input and the attempt to read a character will return it - hence no wait for input. To discard the remaining, unused, input you can use <code>fpurge</code>. E.g.:</p> <pre><code>#include &lt;stdio.h&gt; int main(int argc, char* argV[]) { int selection = 0; fputs("\n1. Add Account \n2. Remove Account \n3. Modify Account \nWhat would you like to do?: ", stdout); scanf("%i", &amp;selection); if (selection == 1) { fputs("\nEnter account owner: ", stdout); fpurge(stdin); // skip any input left in the buffer as %c takes the very next character and does not skip whitespace char accountOwner; scanf("%c", &amp;accountOwner); fputs("\nEnter opening balance: ", stdout); float openingBalance; scanf("%f", &amp;openingBalance); printf("%c - %f\n", accountOwner, openingBalance); } } </code></pre> <p>Note that reading in character strings does skip whitespace, so if your account owner was a string you would not need the <code>fpurge</code>.</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