Pointer to the null-terminated input string to be parsed.
2nd Parameter Type : const char *
Pointer to read-only string
2nd Parameter
A null-terminated format string specifying how to interpret the input string, containing format specifiers like `%d`, `%s`, or `%f`.
3rd Parameter Type : ...
Represents a variable number of arguments in a function. Used in functions like `printf` or `fprintf` to accept additional parameters beyond those explicitly declared.
3rd Parameter
A variable number of pointers to variables where the parsed input values will be stored.
Read more about parameters of sscanf in parameters section
The sscanffunction in C language Reads formatted input from a string.
The sscanf function reads formatted input from a string. It parses the C string str interpreting its content according to the format specified in format, which follows the same specifications as those for scanf. The resulting values are stored in the locations pointed by the additional arguments.
The sscanffunction takes 3
parameters:
•
const char * `str`: Pointer to the null-terminated input string to be parsed.
•
const char * `format`: A null-terminated format string specifying how to interpret the input string, containing format specifiers like `%d`, `%s`, or `%f`.
•
... `args`: A variable number of pointers to variables where the parsed input values will be stored.
Parses the input string `str` according to the `format` string and stores the converted values into the variables pointed to by `args`. Returns the number of successfully matched and assigned input items, or `EOF` if an input failure occurs before any items are matched.
The sscanf function return value :
Returns the number of items successfully filled
This count can match the expected number of items or be less (even zero) in case of a matching failure
EOF is returned if the end of the input string is reached before any conversion
Output
This example demonstrates basic usage of sscanf to parse a string containing a name, age, and height.