title: C Scanf: What does a return value of -1 mean?
body: <p>I'm writing a program that scans input from stdin (well it's supposed to anyways). At a certain point in the program, I need to scan an int using scanf. I've tried a few other functions as well and they all seem to result in the same error - they are returning -1. I assume this means there was some error in gathering data/variable assignment, but I can not find documentation on what kind of error this indicates. The code I wrote is shown below:</p>
  
  <pre><code>int selection = 4; //default value for selection - it has no meaning.
  //printf("DATA SET ANALYSIS\n1. Show all the data.\n2. Calculate the average for an experiment.\n3. Calculate the averae across all experiments.\n4. Quit. \nSelection:__\n");
  printf("Return value of scanf: %d\n", scanf("%d", &amp;selection));
  printf("Return value of getchar: %d\n", getchar());
  printf("Unchanged value of selection: %d\n", selection);
  </code></pre>
  
  <p>Which produces the following output:</p>
  
  <pre><code>Return value of scanf: -1
  Return value of getchar: -1
  Unchanged value of selection: 4
  </code></pre>
  
  <p>What is the source and meaning of this error? I am choosing not to put up the rest of my code. If it is impossible to assess the error without the rest of the code, I can put that up in an edit, but as I'm not sure of the source of the error, that would involve a lot of code. Thank you for any solutions.</p>