sscanf, swscanf (Windows CE 5.0)

Send Feedback

Developing an Application > Microsoft C Run-time Library for Windows CE > Run-time Library Reference

Read formatted data from a string.

int sscanf( const char *buffer, const char *format [, argument ] ... );int swscanf( const wchar_t *buffer, const wchar_t *format [, argument ] ... );

Parameters

  • buffer
    Stored data.
  • format
    Format-control string.
  • argument
    Optional arguments.

Return Values

Each of these functions returns the number of fields successfully converted and assigned; the return value does not include fields that were read but not assigned. A return value of 0 indicates that no fields were assigned. The return value is EOF for an error or if the end of the string is reached before the first conversion.

Remarks

These functions are supported by all versions of the C run-time libraries.

The sscanf function reads data from buffer into the location 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 argument 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. If copying takes place between strings that overlap, the behavior is undefined.

swscanf is a wide-character version of sscanf; the arguments to swscanf are wide-character strings. sscanf does not handle multibyte hexadecimal characters. swscanf does not handle Unicode fullwidth hexadecimal or "compatibility zone" characters. Otherwise, swscanf and sscanf behave identically.

The following table shows generic-text routine mappings for this function.

TCHAR.H Routine _UNICODE Defined
_stscanf swscanf

For more information about TCHAR.H routines, see Generic Text Mappings.

Example

Description

This program uses sscanf to read data items from a string named tokenstring, then displays them.

Code

#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 );
}
// Output
String    = 15
Character = 1
Integer:  = 15
Real:     = 15.000000

Requirements

OS Versions: Windows CE 2.0 and later.

Header: stdio.h, stdlib.h.

Link Library: coredll.dll.

See Also

fscanf | scanf | sprintf | _snprintf

Send Feedback on this topic to the authors

Feedback FAQs

© 2006 Microsoft Corporation. All rights reserved.