swscanf() — Read Wide Character Data

Format

#include <wchar.h>
int swscanf(const wchar_t *buffer, const wchar_t *format, argument-list);

Language Level: ANSI

Threadsafe: Yes.

Locale Sensitive: The behavior of this function might be affected by the LC_CTYPE and LC_NUMERIC categories of the current locale. The behavior might also be affected by the LC_UNI_CTYPE and LC_UNI_NUMERIC categories of the current locale if LOCALETYPE(*LOCALEUCS2) or LOCALETYPE(*LOCALEUTF) is specified on the compilation command. This function is not available when LOCALETYPE(*CLD) is specified on the compilation command. For more information, see Understanding CCSIDs and Locales.

Wide Character Function: See Wide Characters for more information.

Description

The swscanf() function is equivalent of the fwscanf() function, except that the argument buffer specifies a wide string from which the input is to be obtained, rather than from a stream. Reaching the end of the wide string is equivalent to encountering end-of-file for the fwscanf() function.

Return Value

The swscanf() 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 when the end of the string is encountered before anything is converted.

The value of errno may be set EINVAL, invalid argument.

Example that uses swscanf()

This example uses the swscanf() function to read various data from the string ltokenstring, and then displays that data.

#include <wchar.h>                                     
#include <stdio.h>                                        
                                                          
wchar_t *ltokenstring = L"15 12 14";                      
int i;                                                    
float fp;                                                 
char s[10];                                               
char c;                                                   
                                                          
int main(void)                                            
{                                                         
   /* Input various data                                           */
  
   swscanf(ltokenstring, L"%s %c%d%f", s, &c, &i, &fp);   
                                                          
   /* If there were no space between %s and %c,        */  
   /* swscanf would read the first character following */ 
   /* the string, which is a blank space.                      */  
                                                          
   printf("string = %s\n",s);                             
   printf("character = %c\n",c);                          
   printf("integer = %d\n",i);                            
   printf("floating-point number = %f\n",fp);             
                                                          
}

Related Information



[ Top of Page | Previous Page | Next Page | Contents | Index ]