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 ...

Get C Programming: Visual Quickstart Guide now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.