Namespaces
Variants

fwide

From cppreference.net
< c ‎ | io
Definiert im Header <wchar.h>
int fwide ( FILE * stream, int mode ) ;
(seit C95)

Wenn mode > 0 , wird versucht, den stream breitorientiert zu machen. Wenn mode < 0 , wird versucht, den stream byteorientiert zu machen. Wenn mode == 0 , wird nur die aktuelle Ausrichtung des Streams abgefragt.

Wenn die Ausrichtung des Streams bereits festgelegt wurde (durch Ausführung der Ausgabe oder durch einen früheren Aufruf von fwide ), tut diese Funktion nichts.

Inhaltsverzeichnis

Parameter

stream - Zeiger auf den C-I/O-Stream, der geändert oder abgefragt werden soll
mode - Ganzzahlwert größer als Null, um den Stream breit zu setzen, kleiner als Null, um den Stream schmal zu setzen, oder Null, um nur abzufragen

Rückgabewert

Eine ganze Zahl größer als null, wenn der Stream nach diesem Aufruf breitorientiert ist, kleiner als null, wenn der Stream nach diesem Aufruf byteorientiert ist, und null, wenn der Stream keine Orientierung hat.

Beispiel

Der folgende Code setzt und setzt die Stream-Orientierung zurück.

#include <stdio.h>
#include <stdlib.h>
#include <wchar.h>
void show_orientation(int n)
{
    n < 0 ? puts("\tnarrow orientation"):
    n > 0 ? puts("\twide orientation"):
            puts("\tno orientation");
}
void try_read(FILE* fp)
{
    int c = fgetc(fp);
    c == EOF
        ? printf("\tnarrow character read failed\n")
        : printf("\tnarrow character read '%c'\n", c);
    wint_t wc = fgetwc(fp);
    wc == WEOF
        ? printf("\twide character read failed\n")
        : printf("\twide character read '%lc'\n", wc);
}
int main(void)
{
    enum fwide_orientation { narrow = -1, query, wide };
    FILE* fp = fopen("main.cpp", "r");
    if (!fp)
    {
        perror("fopen() failed");
        return EXIT_FAILURE;
    }
    puts("1) A newly opened stream has no orientation.");
    show_orientation(fwide(fp, query));
    puts("2) Establish byte orientation.");
    show_orientation(fwide(fp, narrow));
    try_read(fp);
    puts("3) Only freopen() can reset stream orientation.");
    if (freopen("main.cpp", "r", fp) == NULL)
    {
       perror("freopen() failed");
       return EXIT_FAILURE;
    }
    puts("4) A reopened stream has no orientation.");
    show_orientation(fwide(fp, query));
    puts("5) Establish wide orientation.");
    show_orientation(fwide(fp, wide));
    try_read(fp);
    fclose(fp);
}

Mögliche Ausgabe:

1) A newly opened stream has no orientation.
        no orientation
2) Establish byte orientation.
        narrow orientation
        narrow character read '#'
        wide character read failed
3) Only freopen() can reset stream orientation.
4) A reopened stream has no orientation.
        no orientation
5) Establish wide orientation.
        wide orientation
        narrow character read failed
        wide character read '#'

Referenzen

  • C23-Standard (ISO/IEC 9899:2024):
  • 7.29.3.5 Die fwide-Funktion (S.: TBD)
  • C17-Standard (ISO/IEC 9899:2018):
  • 7.29.3.5 Die fwide-Funktion (S. 309)
  • C11-Standard (ISO/IEC 9899:2011):
  • 7.29.3.5 Die fwide-Funktion (S: 423)
  • C99-Standard (ISO/IEC 9899:1999):
  • 7.24.3.5 Die fwide-Funktion (S: 369)

Siehe auch

öffnet eine Datei
(Funktion)