User Tools

Site Tools


Sidebar

Programming Reference/Librarys

Question & Answer

Q&A is closed







c:wchar.h:fgetws

fgetws

   #include <wchar.h>
   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 <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;
}

output - fgetws example code

  
  ./fgetws 
  read char: asdfjklöä#

on the occasion of the current invasion of Russia in Ukraine

Russian Stop this War
c/wchar.h/fgetws.txt · Last modified: 2024/02/16 01:05 (external edit)

Impressum Datenschutz