 <p>You have to just give one space before %c in scanf </p> <pre><code>scanf(" %c",&amp;ch); </code></pre> <p>This is because after giving the input we pressed enter that enter is stored in buffer and this read again by our program, some time we clear we flush our input/output buffer you can check in Linux <code>fflush()</code>I think so is the function, there is lots of way but this is the easiest way that I know. Hope useful for you.</p>