fwide
|
Défini dans l'en-tête
<wchar.h>
|
||
|
int
fwide
(
FILE
*
stream,
int
mode
)
;
|
(depuis C95) | |
Si mode > 0 , tente de rendre le stream orienté large. Si mode < 0 , tente de rendre le stream orienté octet. Si mode == 0 , ne fait que consulter l'orientation actuelle du flux.
Si l'orientation du flux a déjà été déterminée (en exécutant une sortie ou par un appel antérieur à
fwide
), cette fonction ne fait rien.
Table des matières |
Paramètres
| stream | - | pointeur vers le flux d'E/S C à modifier ou interroger |
| mode | - | valeur entière supérieure à zéro pour définir le flux en mode large, inférieure à zéro pour définir le flux en mode étroit, ou zéro pour interrogation uniquement |
Valeur de retour
Un entier supérieur à zéro si le flux est orienté large après cet appel, inférieur à zéro si le flux est orienté octet après cet appel, et zéro si le flux n'a aucune orientation.
Exemple
Le code suivant définit et réinitialise l'orientation du flux.
#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); }
Sortie possible :
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 '#'
Références
- Norme C23 (ISO/IEC 9899:2024):
-
- 7.29.3.5 La fonction fwide (p: TBD)
- Norme C17 (ISO/CEI 9899:2018) :
-
- 7.29.3.5 La fonction fwide (p : 309)
- Norme C11 (ISO/IEC 9899:2011):
-
- 7.29.3.5 La fonction fwide (p: 423)
- Norme C99 (ISO/CEI 9899:1999) :
-
- 7.24.3.5 La fonction fwide (p: 369)
Voir aussi
|
(C11)
|
ouvre un fichier
(fonction) |
|
Documentation C++
pour
fwide
|
|