Reads formatted data from a string.
#include <stdio.h>
int sscanf( const char *buffer, const char *format[[, argument]] ... );
buffer | Stored data | |
format | Format-control string | |
argument | Optional arguments |
The sscanf function reads data from buffer into the locations given by each argument. Every argument must be a pointer to a variable with a type that corresponds to a type specifier in format. The format controls the interpretation of the input fields and has the same form and function as the format argument for the scanf function; see scanf for a complete description of format.
The sscanf function 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 for an attempt to read at end-of-string. A return value of 0 means that no fields were assigned.
Standards:ANSI, UNIX
16-Bit:DOS, QWIN, WIN
32-Bit:DOS32X
/* SSCANF.C: This program uses sscanf to read data items from
* a string named tokenstring, then displays them.
*/
#include <stdio.h>
void main( void )
{
char tokenstring[] = "15 12 14...";
char s[81];
char c;
int i;
float fp;
/* Input various data from tokenstring: */
sscanf( tokenstring, "%s", s );
sscanf( tokenstring, "%c", &c );
sscanf( tokenstring, "%d", &i );
sscanf( tokenstring, "%f", &fp );
/* Output the data read */
printf( "String = %s\n", s );
printf( "Character = %c\n", c );
printf( "Integer: = %d\n", i );
printf( "Real: = %f\n", fp );
}
String = 15
Character = 1
Integer: = 15
Real: = 15.000000