User Tools

Site Tools


c:wchar.h:fgetws

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

c:wchar.h:fgetws [2013/01/22 22:02]
c:wchar.h:fgetws [2024/02/16 01:05] (current)
Line 1: Line 1:
 +{{keywords>wiki library source code example reference}}
 +===== fgetws =====
 +
 +<code c>
 +   #include <wchar.h>
 +   wchar_t *fgetws(wchar_t *restrict, int, FILE *stream);
 +</code>
 +
 +
 +=== 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 =====
 +<code c>
 +/* 
 + * 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;
 +}
 +
 +</code>
 +
 +====  output - fgetws example code ====
 +    
 +    ./fgetws 
 +    read char: asdfjklöä#
 +
 +
 +
  

on the occasion of the current invasion of Russia in Ukraine

Russian Stop this War

Impressum Datenschutz