Name
fgetwc, getwc, getwchar
- read a wide character from a FILE stream
Library
libc.lib
Synopsis
|
wint_t
fgetwc (FILE *stream);
|
|
wint_t
getwc (FILE *stream);
|
Return values
If successful, these routines return the next wide character
from the
stream.
If the stream is at end-of-file or a read error occurs,
the routines return
WEOF.
The routines
feof
and
ferror
must be used to distinguish between end-of-file and error.
If an error occurs, the global variable
errno
is set to indicate the error.
The end-of-file condition is remembered, even on a terminal, and all
subsequent attempts to read will return
WEOF
until the condition is cleared with
clearerr.
Detailed description
The
fgetwc
function
obtains the next input wide character (if present) from the stream pointed at by
stream,
or the next character pushed back on the stream via
ungetwc.
The
getwc
function
acts essentially identical to
fgetwc.
The
getwchar
function
is equivalent to
getwc
with the argument
stdin.
Examples
/* Illustrates how to use fgetwc API */
#include <stdio.h>
#include <wchar.h>
wint_t example_fgetwc(void)
{
FILE *fp = NULL;
wint_t retval;
/* opening the input file */
fp = fopen("input.txt","r");
if(fp == NULL)
{
wprintf(L"Error: File open\n");
return (-1);
}
/* Read a character from the opened file */
retval = fgetwc(fp);
/* Close the file open for reading */
fclose(fp);
/* return the character read from the file */
return (retval);
}
/* Illustrates how to use getwc API */
#include <stdio.h>
#include <wchar.h>
wint_t example_getwc(void)
{
FILE *fp = NULL;
wint_t retval;
/* opening the input file */
fp = fopen("input.txt","r");
if(fp == NULL)
{
wprintf(L"Error: File open\n");
return (-1);
}
/* Read a character from the opened file */
retval = getwc(fp);
/* Close the file open for reading */
fclose(fp);
/* return the character read from the file */
return (retval);
}
/* Illustrates how to use getwchar API */
#include <stdio.h>
#include <wchar.h>
wint_t example_getwchar(void)
{
wint_t retval;
/* Read a character from standard input */
retval = getwchar();
/* return the character read */
return (retval);
}
See also
ferror,
fopen,
fread,
getc,
putwc,
ungetwc
Feedback
For additional information or queries on this page send feedback
© 2005-2007 Nokia
|
|