How to use sscanf In C Language
Reads data from s and stores it in the places specified by the additional arguments in the parameter format. Below is the C program to convert char to int using sscanf.
Example:
C
// C program to demonstrate conversion of // char to int using sscanf() #include <stdio.h> // Driver code int main() { const char * s = "136" ; int x; sscanf (s, "%d" , &x); printf ( "\nThe integer value of x is %d " , x); return 0; } |
Output
The integer value of x is 136
C Program For Char to Int Conversion
There are 3 ways to convert the char to int in C language as follows:
- Using Typecasting
- Using sscanf()
- Using atoi()
Let’s discuss each of these methods in detail.