Created
March 10, 2014 05:33
-
-
Save akayj/9459986 to your computer and use it in GitHub Desktop.
Read number from command line, ignore char.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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