I am using scanf() to get a set of ints from the user. But I would like the user to supply all 4 ints at once instead of 4 different promps. I know I can get one value by doing:
scanf( "%i", &minx);
But I would like the user to be able to do something like:
Enter Four Ints: 123 234 345 456
Is it possible to do this?
Inputting Multiple ValuesIf you have multiple format specifiers within the string argument of scanf, you can input multiple values. All you need to do is to separate each format specifier with a DELIMITER - a string that separates variables.
scanf() reads data from the keyboard. To read in more than one value just use the two individual formats separated by spaces such as "%d %d".
# Taking multiple inputs in a single line. # and type casting using list() function. x = list(map(int, input("Enter multiple values: "). split()))
To read multiple string values from a single line entered by user in a specified format via standard input in C language, use scanf() function and pass the format and variables as arguments. scanf() reads input from stdin(standard input), according to the given format and stores the data in the given arguments.
You can do this with a single call, like so:
scanf( "%i %i %i %i", &minx, &maxx, &miny, &maxy);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With