wscanf - C wchar.h

C examples for wchar.h:wscanf

Type

function

From


<cwchar>
<wchar.h>

Description

Read formatted data from stdin

Prototype

int wscanf (const wchar_t* format, ...);

Parameters

Parameter Description
format a format string that follows the same specifications as format in scanf

Return Value

On success, the function returns the number of items of the argument list successfully filled.

On error, EOF is returned.

Demo Code


#include <wchar.h>

int main ()//from  ww w .j a  v  a  2s  .c o  m
{
  wchar_t str [80];
  int i;

  wprintf (L"Enter your family name: ");

  wscanf (L"%ls",str);

  wprintf (L"Enter your age: ");

  wscanf (L"%d",&i);

  wprintf (L"%ls, %d years old.\n",str,i);

  return 0;
}

The following code reads integer.

Demo Code


#include <wchar.h>

int main ()//www .j  a  va  2s  . co m
{
  wchar_t str [80];
  int i;


  wprintf (L"Enter a hexadecimal number: ");

  wscanf (L"%x",&i);

  wprintf (L"You have entered %#x (%d).\n",i,i);


  return 0;
}

Related Tutorials