User Tools

Site Tools


Programming Reference/Librarys

Question & Answer

Q&A is closed

to support this page (eg 0,42 € or so) Thanks.


   #include <wchar.h>
   wchar_t *fgetws(wchar_t *restrict, int, FILE *stream);


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
#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
    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" );
    return 0;

output - fgetws example code

  read char: asdfjklöä#
c/wchar.h/fgetws.txt · Last modified: 2013/01/22 22:02 (external edit)