#C 语言标准库函数 fgetws
#include <wchar.h>
wchar_t *fgetws(wchar_t *restrict s, int n, FILE *restrict stream);
说明
从流中读取一行宽字符,最多保存 n - 1 个宽字符。成功读到的换行符也会存入数组。
宽字符 I/O 使用流定向。一个流确定定向后,应按相同定向操作。
自 C95 起提供。
参数
s- 接收宽字符的可写数组。n- 数组容量,按宽字符数计,须大于零。stream- 可进行宽字符 I/O 的有效流。
返回值
- 成功返回 s 并补写空宽字符。首次读到字符前遇到文件末尾或出现错误时返回空指针。
#示例
#include <wchar.h>
#include <stdio.h>
int main(void)
{
FILE *stream = tmpfile();
if (stream == NULL) {
return 1;
}
if (fputws(L"A\n", stream) < 0 || fseek(stream, 0, SEEK_SET) != 0) {
fclose(stream);
return 1;
}
wchar_t text[8];
int ok = fgetws(text, 8, stream) != NULL && text[0] == L'A';
int closed = fclose(stream);
return !ok || closed != 0;
}