title: getchar and scanf buffer issues. getchar not storing the correct value
body: <p>I'm pretty new to programming and I understand that scanf() has some quirks to it. Namely, when it detects characters that don't match up with its conversion specifiers, it immediately returns and puts the offending characters back into a buffer in order to be read by another scanf() call or by some other function which can access the buffer.
  However, I'm doing a book exercise and the code behavior is odd.</p>
  <pre><code>    float total = 0, operand = 0;
      char operator = 0;
  
      printf(&quot;Enter an expression: &quot;);
  
      scanf(&quot;%f &quot;, &amp;total);
  
      while ((operator = getchar()) != '\n') {
          scanf(&quot;%f&quot;, &amp;operand);
          switch (operator) {
              case '+':
                  total += operand;
                  break;
              case '-':
                  total -= operand;
                  break;
              case '*':
                  total *= operand;
                  break;
              case '/':
                  total /= operand;
                  break;
          }
          printf(&quot;Value of operator: %c\n&quot;, operator);
          printf(&quot;Operand: %f\n&quot;, operand);
      }
  
      printf(&quot;Value of expression: %f\n&quot;, total);
  
  </code></pre>
  <p>The two printf calls are for testing. An input of: &quot;1 + 5 + 9\n&quot; results in:</p>
  <pre><code>Value of operator: +
  Operand: 5.000000
  Value of operator:  
  Operand: 5.000000
  Value of operator:  
  Operand: 9.000000
  Value of expression: 6.000000
  </code></pre>
  <p>So, the program seems to go like this:
  scanf() reads 1 into 'total', pairs the space after it with the space in the format string, encounters the '+', then puts it back into the buffer and returns.</p>
  <p>Then:</p>
  <p>Loop 1 - getchar() reads the leftover '+' and places it into 'operator'. scanf() reads 5, encounters the space, puts it back into the buffer, and returns.</p>
  <p>Loop 2 - getchar() reads the leftover ' ', and places it into 'operator' scanf() encounters '+' and immediately returns and places it back into the buffer.</p>
  <p>Here's where things don't align with my understanding. At the start of loop 3, getchar() should encounter the '+' and store it into 'operator'. Instead, it's skipped completely, and it makes no sense to me.</p>