O'Reilly logo

C Programming: Visual Quickstart Guide by Marc Liyanage, Larry Ullman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Reading Multiple Inputs

Reading in single chunks of input is great, but being able to read in multiple pieces of input at once would be better. This can be accomplished using the scanf() function, which can read multiple inputs. For example:

int num1, num2;
scanf("%d %d", &num1, &num2);

That line of code will read in two integer values, separated by a space, and assign them to the num1 and num2 variables.

To demonstrate this, the following example will take both a number (the temperature) and the letter F or C (which determines whether that value is in degrees Fahrenheit or degrees Celsius). The application will then convert that number to the other format.

To read in multiple inputs at once

1.
Create a new file or project in your text editor ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required