C programming stdio.h function - int scanf(const char *format, ...)

https://w‮.ww‬theitroad.com

The scanf function is used to read formatted input from the standard input stream (stdin). It takes a format string and a variable number of pointer arguments, which correspond to the types of data to be read.

Here's the function signature and a brief description of the parameters:

int scanf(const char *format, ...);
  • format: a string that contains format specifiers that control how input is read.
  • ...: variable number of arguments that are pointers to the memory locations where the input values should be stored.

The scanf function scans input from the standard input stream (stdin) and matches the input with the specified format specifiers. It returns the number of input items successfully matched and assigned. If an error occurs, it returns EOF.

Here's an example usage of scanf:

int age;
char name[20];
printf("Enter your name and age: ");
scanf("%s %d", name, &age);
printf("Your name is %s and your age is %d.\n", name, age);

In this example, the user is prompted to enter their name and age. The scanf function reads the input from the standard input stream and stores the name in the name character array and the age in the age integer variable. Finally, the program prints out the values that were read using printf.