Getting multiple values with scanf()

Josh Curren picture Josh Curren · Sep 11, 2009 · Viewed 209.1k times · Source

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?

Answer

Reed Copsey picture Reed Copsey · Sep 11, 2009

You can do this with a single call, like so:

scanf( "%i %i %i %i", &minx, &maxx, &miny, &maxy);