Skip to content

Instantly share code, notes, and snippets.

@akayj
Created March 10, 2014 05:33
Show Gist options
  • Save akayj/9459986 to your computer and use it in GitHub Desktop.
Save akayj/9459986 to your computer and use it in GitHub Desktop.
Read number from command line, ignore char.
#include <stdio.h>
int main(int argc, char *argv[])
{
int input_var = 0;
int count;
do {
printf("Enter a number (-1 = quit): ");
count = scanf("%d", &input_var);
if (count == 0 || count == EOF) {
puts("You entered a non-numeric. Exiting...");
break;
}
if (input_var != -1) {
printf("You have entered %d\n", input_var);
}
} while (input_var != -1);
puts("All done!");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment