![]() |
VOOZH | about |
The scanf() function is used to take input from the console. It is defined in <stdio.h> header file and takes const char* and variable argument list as parameters.
In this article, we will learn how to implement your own custom scanf() function in C language. For this, we need to have a firm grasp of the following concepts:
Prerequisites:Variadic Functions in C, Strings in C, Format Specifiers in C
Example
Statement 1: scanf("%s %d", str, &in);
Input: Hello_world 10
str = Hello_world, in = 10
Statement 2: scanf("%d %s %f", &in, str, &fl);
Input: 10 Geeks 1.1
in = 10, str = Geeks, fl = 1.1
Input
2023 g Article 4.04
Output
2023 g Article 4.040000
The time complexity of the following function is: O(n), where,
Must Read - scanf() in C