title: Assigning a user-entered char to a variable
body: <p>I'm having a few issues successfully storing a user entered <code>char</code> to a variable, the variable which then needs to be used in a different part of the program.</p>
  
  <p>The program in question is supposed to do the following things:</p>
  
  <ul>
  <li>Take a set of user entered values</li>
  <li>Place those values into an array of predetermined size</li>
  <li>Prompt the user if they would like to see the array</li>
  <li>If 'Y', pretty print the array.</li>
  </ul>
  
  <p>I will show you the second part of the program here, in code fragment form, since the first part (placing the values into the array) works fine:</p>
  
  <pre><code>char input, confirm;
  printf("Would you like to view the array? Y/N: ");
      while ((input = getchar()) != EOF){
          confirm = putchar(input);
      if (confirm == 'Y'){
          printf("[");
          for (i = 0; i &lt; maxvals; i++){
              if (i != maxvals - 1){
                  printf("%d,", A[i]);
              }
              else{
                  printf("%d", A[i]);
              }
          }
          printf("]");
      }
      printf("\n");
  </code></pre>
  
  <p>All variables are obviously pre-declared. Lines 2 and 3 are where I'm having an issue right now. </p>
  
  <p>When I try to run the program, I get:</p>
  
  <pre><code>$ arrays.exe
  Enter as many as 10 values, ^D to end
  1 2 3
  ^D
  3 values read into array
  Would you like to view the array? Y/N: ♦
  Y
  Y
  </code></pre>
  
  <p>Note the program just repeats what the user entered. I tried this also (in place of the while loop):</p>
  
  <pre><code>confirm = getchar();
  </code></pre>
  
  <p>But this just terminates the program. I'm also worried that my <code>if (confirm == "Y")</code> line won't work, but based on my previous programming experience I think it should?</p>
  
  <p>I'm pretty sure I've given all the necessary code but if you want the entire program please tell me so I can edit this.</p>
  
  <p>EDIT:</p>
  
  <p>No one mentioned scanf. It solved the problem. Here is the working code for future reference:</p>
  
  <pre><code>while (scanf("%c", &amp;confirm) == 1){
      if (confirm == 'Y'){
      printf("[");
      for (i = 0; i &lt; n; i++){
          if (i != n - 1){
              printf("%d,", A[i]);
           }
           else{
              printf("%d", A[i]);
           }
      }
      printf("]");
      break;
      }
  }
  return 0;
  </code></pre>