411 REFERENCE · Wikibooks
C programming/wchar.h/fgetws
Reference material by Wikibooks contributors. This retains its source identity and is not 411 news reporting.
fgetws is a function in the C programming language. It is wide-character version of the function fgets. The w in fgetws is for wide. A string is read as a multibyte-character or a wide character string by fgetws depending on whether the stream is opened in text/binary mode respectively. The fgetws subroutine reads characters from the input stream, converts them to the corresponding wide character codes, and places them in the array pointed to by the string parameter.
The subroutine continues until either:
The number of characters specified by the number parameter '-1' are read
The subroutine encounters a newline or EOF character.
The fgetws subroutine terminates the wide character string with a NULL wide character.
Syntax
#include <stdio.h>
#include <wchar.h>
wchar_t *fgetws(
wchar_t *string;
int n;
FILE *stream ;
);
Parameters
fgetws has three parameters:
string - a string used to provide storage location for data
n - the maximum number of readable characters
stream - a FILE pointer
Requirements
Although fgetws is wider relative to fgets, it can be compiled by an additional optional header along with stdio.h called wchar.h. However, fgets requires stdio.h compulsorily. Hence, fgetws provides option.
Return value
Just as fgets function, fgetws function also returns the same value string i.e. a ws is returned on success. The error condition is taken care-of by this function using a NULL pointer. A Null pointer is returned to the function-called for error or even at EOF(end of file). One can use also use the feof or ferror for error determination.
Compatibility
ubuntu, fedora, ANSI, Win 98, Win Me, Win NT, Win 2000, Win XP
References
http://pubs.opengroup.org/onlinepubs/009695399/functions/fgetws.html
http://www.freebsd.org/cgi/man.cgi?query=fgetws&apropos=0&sektion=0&manpath=FreeBSD+7.1-RELEASE&format
http://msdn.microsoft.com/en-us/library/c37dh6kf(v=vs.71).aspx
http://publib.boulder.ibm.com/infocenter/pseries/v5r3/index.jsp?topic=/com.ibm.aix.basetechref/doc/basetrf1/getws.htm
deep