{{keywords>wiki library source code example reference}}
===== fgetws =====
#include
wchar_t *fgetws(wchar_t *restrict, int, FILE *stream);
=== Description ===
fgetws reads wide characters into "*restrict" from "stream"\\
fgetws will also stop reading if it encounters a newline character. In which case,\\
the newline character will put into the string as long as the number of characters\\
does not exceed "length - 1". \\
\\
The function will also stop reading if it reaches the end of the stream. \\
If an error or EOF occurs, the function returns NULL instead of a widechar string Depending\\
on whether the mode is binary or text, the function will read "*stream" as a wide-character or multibyte-character string, respectively.
===== fgetws C Sourcecode Example =====
/*
* fgetws example code
* http://code-reference.com/c/wchar.h/fgetws
*/
#include /* including standard library */
//#include /* uncomment this for Windows */
#include
#include // nessesary for this example
int main( void )
{
FILE* stream = fopen("test.txt", "r");
// set locale
setlocale(LC_ALL,"");
if (!stream) {
wprintf(L"could not open the file\n");
return 1;
}
wchar_t string[20];
wchar_t* wpreturn = fgetws(string, 20, stream);
if (wpreturn != NULL) {
wprintf( L"read char: %ls\n", string);
}
else {
wprintf( L"read error\n" );
}
fclose(stream);
return 0;
}
==== output - fgetws example code ====
./fgetws
read char: asdfjklöä#