132k views
2 votes
How I get input from the user in C? Here's my code now:

int main(void)
{
int number;
// How to read in a number here.
}

1 Answer

4 votes

You must use “scanf” statement to read the input. You must also include the necessary header file to use all the built-in functions in any programming languages.

scanf(“%d”, &number);

Since “scanf” is a statement it must end with the semicolon. “scanf” accepts two parameters, first the type of value and second is the address of the variable to store the given input.

Here “&” represents the address of the given variable. “%d” is used for integer, “%f” is used for float, “%s” is used to receive string inputs, etc.

User Damian Senn
by
5.1k points