wscanf ()- 使用宽字符格式字符串读取数据

格式

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

语言级别

ANSI

线程安全

语言环境敏感

此函数的行为可能受当前语言环境的 LC_CTYPE 和 LC_NUMERIC 类别影响。 如果在编译命令上指定了 LOCALETYPE (*LOCALEUCS2) 或 LOCALETYPE (*LOCALEUTF) ,那么此行为也可能受到当前语言环境的 LC_UNI_CTYPE 和 LC_UNI_NUMERIC 类别的影响。 当在编译命令上指定 LOCALETYPE (*CLD) 时,此功能不可用。 有关更多信息,请参阅 了解 CCSID 和语言环境

集成文件系统界面

当在编译命令上指定 SYSIFCOPT (*NOIFSIO) 时,此功能不可用。

宽字符函数

有关更多信息,请参阅 宽字符

描述

wscanf() 函数等同于在 wscanf() 函数的自变量之前插入了自变量 stdinfwscanf() 函数。

返回值

如果在任何转换之前发生输入故障,那么 wscanf() 函数将返回宏 EOF 的值。

否则, wscanf() 函数将返回分配的输入项数。 在早期匹配失败的情况下,它可以小于所提供的值,甚至为零。

示例

此示例扫描各种类型的数据。
#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
   ********************************************************************/
 

相关信息