Syntax
#include <stdio.h> int sscanf(const char *buffer, const char *format, argument-list);Description
sscanf reads data from buffer into the locations given by argument-list. Each argument must be a pointer to a variable with a type that corresponds to a type specifier in the format-string. See scanf for a description of the format-string.
sscanf returns the number of fields that were successfully converted and assigned. The return value does not include fields that were read but not assigned.
The return value is EOF when the end of the string is encountered before anything is converted.
This example uses sscanf to read various data from the string tokenstring, and then displays that data.
#include <stdio.h> #define SIZE 81 char *tokenstring = "15 12 14"; int i; float fp; char s[SIZE]; char c; int main(void) { /* Input various data */ sscanf(tokenstring, "%s %c%d%f", s, &c, &i, &fp); /* If there were no space between %s and %c, */ /* sscanf would read the first character following */ /* the string, which is a blank space. */ /* Display the data */ printf("string = %s\n", s); printf("character = %c\n", c); printf("integer = %d\n", i); printf("floating-point number = %f\n", fp); return 0; /**************************************************************************** The output should be: string = 15 character = 1 integer = 2 floating-point number = 14.000000 ****************************************************************************/ } /***************** Output should be similar to: ***************** string = 15 character = 1 integer = 2 floating-point number = 14.000000 */Related Information