wscanf() — Read Data Using Wide-Character Format String

Format

#include <stdio.h>
int wscanf(const wchar_t *format,...);

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.

Integrated File System Interface: This function is not available when SYSIFCOPT(*NOIFSIO) is specified on the compilation command.

Wide Character Function: See Wide Characters for more information.

Description

The wscanf() function is equivalent to the fwscanf() function with the argument stdin interposed before the arguments of the wscanf() function.

Return Value

If an input failure occurs before any conversion, the wscanf() function returns the value of the macro EOF.

Otherwise, the wscanf() function returns the number of input items assigned. It can be fewer than provided for, or even zero, in the event of an early matching failure.

Example that uses wscanf()

This example scans various types of data.

#include <stdio.h>
#include <wchar.h>
 
int main(void)
{
   int i;
   float fp;
   char c,s[81];
 
   printf("Enter an integer, a real number, a character and a string : \n");
   if (wscanf(L"%d %f %c %s", &i, &fp,&c, s) != 4)
      printf("Some fields were not assigned\n");
   else {
      printf("integer = %d\n", i);
      printf("real number = %f\n", fp);
      printf("character = %c\n", c);
      printf("string = %s\n", s);
   }
   return 0;
 
   /********************************************************************
      The output should be similar to:
 
      Enter an integer, a real number, a character and a string :
      12 2.5 a yes
      integer = 12
      real number = 2.500000
      character = a
      string = yes
   ********************************************************************/
}
 

Related Information



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