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 example code * http://code-reference.com/c/wchar.h/fgetws */ #include <stdio.h> /* including standard library */ //#include <windows.h> /* uncomment this for Windows */ #include <wchar.h> #include <locale.h> // 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; }
./fgetws read char: asdfjklöä#