![]() |
In C, sscanf() function stands for “String Scan Formatted”. This function is used for parsing the formatted strings, unlike scanf() that reads from the input stream, the sscanf() function extracts data from a string. In this article, we will learn how to read data using sscanf() function in C. Example: Input: Read Data Using sscanf Function in CIn C, the sscanf() function can be used to read formatted data from a string rather than a standard input or keyboard. Pass the string to be parsed, a format specifier that defines the expected data types and structure of the input string (like %d, %f, %c, etc), and the list of variables where we want to store the formatted data as a parameter to the sscanf() functions to get the parsed string. Syntax of sscanf() in Csscanf(input_str, format, store1, store2, ...); Here,
C Program to Read Data Using sscanf()The below program demonstrates how we can read data using sscanf() function in C.
Output Name: Ram Designation: Manager Age: 30 Time complexity: O(n), where n is the length of the input string. Explanation: In this program, sscanf() reads three items from the string str, so 3 will be assigned to ret. The printf() function is then used to display name, designation, and age.
|
Reffered: https://www.geeksforgeeks.org
C Language |
Related |
---|
![]() |
![]() |
![]() |
![]() |
![]() |
Type: | Geek |
Category: | Coding |
Sub Category: | Tutorial |
Uploaded by: | Admin |
Views: | 12 |