title: How do you prevent blank lines when checking answers in an array in C?
body: <p>I am making a Bingo game in C for a project and have made it through the initial board creation:
  <code>B = 1-20, I = 21-40, N = 41-60, G = 61-80, O = 81-99</code>.
  I have also been able to randomly generate a letter/number pair that doesn't repeat that is to be used to play the game per the following:</p>
  <pre><code>int main()
  {
      srand(time(0));
  
      int rollcount = 0, rollc, rollr, nohund, basec=5, base=20;
      const char BINGO[5] = {'B','I','N','G','O'};
      bool check[101];
  
      //fills check array with falses that will change to true as numbers are picked.        
      for(int i = 0; I &lt; 100; i++) 
          check[i]=false;
      
      //marks free space as true, free = 100 on board
      check[100]=true; 
  
      do
      {
          //test var to prevent duplicate &quot;rolls&quot; until a game is won
          bool reroll=true; 
  
          rollcount++;
  
          //here's where the problem starts
          //This is meant to loop if the number rolled has been rolled before.
          do  
          {
              //getchar();
              if(getchar() == 'q')
              {
                 //future code to display stats and escape game
                 return 0;
              }
  
              rollc = rand() %basec;  //pick random column
  
              //pick random number in range of selected column
              rollr = rand() %base + 1;
              rollr += (rollc * 20);  
  
              //limits last col to 99 instead of 100
              nohund = (rollr == 100 ? rollr -= 1 : rollr);  
  
              if (check[rollr] == false)  //checks if number has been used
              {
                  //prints the number of the roll, column letter, and random number
                  printf(&quot;%d: %c-%d&quot;, rollcount, BINGO[rollc], rollr);
                      
                  check[rollr]=true;  //prevents future use of that number
                  reroll=false;  //escapes loop to roll another number
              }
          }
          //roll current roll again when duplicate is generated
          while(reroll==true);  
      }
      //intended to roll with each press of 'ENTER'
      while(getchar()=='\n');  
  }
  </code></pre>
  <p>I have tried a few things.  As written above, the major problem is if a duplicate is found, it shows the blank line from the <code>getchar()</code> input in the <code>if()</code> statement.  As more numbers are found, wider and wider gaps between lines appear (due to needing more <code>ENTER</code> presses to find a unique number), leaving a mostly blank screen.  With a single <code>ENTER</code> press, I need it to loop until it finds a good number.  If I get rid of all <code>getchar()</code> expressions, the program will do this, and I can press <code>ENTER</code> until I get <code>99</code> unique numbers, but I need to allow to press <code>q</code> to quit the program.</p>
  <p>Example Output</p>
  <pre><code>1: B-15  
  2: G-78  
  3: I-37  
  4: G-62  
  </code></pre>
  <p>To summarize, I need it to display numbers like it does without <code>getchar()</code>, make it through all <code>99</code> possibilities, and let me quit with <code>q</code>.</p>
  <p>Please help, and thank you in advance.</p>