Namensräume
Varianten
Aktionen

fwide

Von cppreference.com
< c‎ | io
 
 
Datei-Ein-/Ausgabe
Typen und Objekte
        
Funktionen
Datei-Zugriff
fwide
(C95)
Unformatierte Ein-/Ausgabe
(C95)(C95)
(C95)
(C95)(C95)
(C95)
(C95)

Formatierte Eingabe
Direkte Ein-/Ausgabe
Formatierte Ausgabe
Dateipositionierung
Fehlerbehandlung
Operationen auf Dateien
 
Definiert in Header <wchar.h>
int fwide( FILE* stream, int mode );
(seit C95)

Wenn mode > 0 ist, wird versucht, den Stream stream als Wide-orientiert festzulegen. Wenn mode < 0 ist, wird versucht, den Stream stream als Byte-orientiert festzulegen. Wenn mode == 0 ist, wird nur die aktuelle Ausrichtung des Streams abgefragt.

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

Inhalt

[edit] Parameter

stream - Zeiger auf den C I/O-Stream, der geändert oder abgefragt werden soll
mode - Ganzzahliger Wert größer als Null, um den Stream als Wide festzulegen, kleiner als Null, um den Stream als Narrow festzulegen, oder Null, um nur abzufragen

[edit] Rückgabewert

Eine Ganzzahl größer als Null, wenn der Stream nach diesem Aufruf Wide-orientiert ist, kleiner als Null, wenn der Stream Byte-orientiert ist, und Null, wenn der Stream keine Ausrichtung hat.

[edit] Beispiel

Der folgende Code legt die Stream-Ausrichtung fest und setzt sie 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 '#'

[edit] Referenzen

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

[edit] Siehe auch

öffnet eine Datei
(Funktion) [bearbeiten]