fwide
| Types and objects | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
헤더 파일에 정의됨
<wchar.h>
|
||
|
int
fwide
(
FILE
*
stream,
int
mode
)
;
|
(C95 이후) | |
만약 mode > 0 이면, stream 을 wide-oriented로 만들려고 시도합니다. 만약 mode < 0 이면, stream 을 byte-oriented로 만들려고 시도합니다. 만약 mode == 0 이면, 스트림의 현재 방향만을 조회합니다.
스트림의 방향이 이미 결정된 경우(출력 실행 또는 이전
fwide
호출에 의해), 이 함수는 아무 작업도 수행하지 않습니다.
목차 |
매개변수
| stream | - | 수정하거나 조회할 C I/O 스트림에 대한 포인터 |
| mode | - | 스트림을 와이드로 설정하려면 0보다 큰 정수 값, 스트림을 나로우로 설정하려면 0보다 작은 정수 값, 또는 조회만 하려면 0 |
반환값
이 호출 이후 스트림이 와이드 지향(wide-oriented)이면 0보다 큰 정수, 바이트 지향(byte-oriented)이면 0보다 작은 정수, 방향성이 없으면 0을 반환합니다.
예제
다음 코드는 스트림 방향을 설정하고 재설정합니다.
#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); }
가능한 출력:
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 '#'
참조문헌
- C23 표준 (ISO/IEC 9899:2024):
-
- 7.29.3.5 fwide 함수 (p: TBD)
- C17 표준 (ISO/IEC 9899:2018):
-
- 7.29.3.5 fwide 함수 (p: 309)
- C11 표준 (ISO/IEC 9899:2011):
-
- 7.29.3.5 fwide 함수 (p: 423)
- C99 표준 (ISO/IEC 9899:1999):
-
- 7.24.3.5 fwide 함수 (p: 369)
참고 항목
|
(C11)
|
파일을 엽니다
(함수) |
|
C++ documentation
for
fwide
|
|