Hi,
I want the user to be able to enter up to 3 integers.... I need to react based on the number they input, so i'm using scanf and tracking the return value. However, when I enter just one integer and press enter, it just moves to the next line and scanf is still running. Shouldn't scanf quit after the user presses enter?
Example:
Code:#include <stdio.h> int main() { int one,two,three; int ret_val = scanf("%d %d %d", &one, &two, &three); if (ret_val == 0) { } else if (ret_val == 1) { printf("one = %d\n",one); } else if (ret_val == 2) { printf("one = %d\ntwo = %d\n",one,two); } else { printf("one = %d\ntwo = %d\nthree = %d\n",one,two,three); } }



LinkBack URL
About LinkBacks



