mbsinit
來自 cppreference.com
在標頭檔案 <wchar.h> 中定義 |
||
int mbsinit( const mbstate_t* ps); |
(自 C95 起) | |
如果 ps
不是空指標,則 mbsinit
函式確定指向的 mbstate_t 物件是否描述了初始轉換狀態。
目錄 |
[編輯] 注意
儘管零初始化的 mbstate_t 始終表示初始轉換狀態,但可能存在其他 mbstate_t 值也表示初始轉換狀態。
[編輯] 引數
ps | - | 指向要檢查的 mbstate_t 物件的指標 |
[編輯] 返回值
0 如果 ps
不是空指標且不表示初始轉換狀態,否則返回非零值。
[編輯] 示例
執行此程式碼
#include <locale.h> #include <string.h> #include <stdio.h> #include <wchar.h> int main(void) { // allow mbrlen() to work with UTF-8 multibyte encoding setlocale(LC_ALL, "en_US.utf8"); // UTF-8 narrow multibyte encoding const char* str = u8"水"; // or u8"\u6c34" or "\xe6\xb0\xb4" static mbstate_t mb; // zero-initialize (void)mbrlen(&str[0], 1, &mb); if (!mbsinit(&mb)) { printf("After processing the first 1 byte of %s,\n" "the conversion state is not initial\n\n", str); } (void)mbrlen(&str[1], strlen(str), &mb); if (mbsinit(&mb)) { printf("After processing the remaining 2 bytes of %s,\n" "the conversion state is initial conversion state\n", str); } }
輸出
After processing the first 1 byte of 水, the conversion state is not initial After processing the remaining 2 bytes of 水, the conversion state is initial conversion state
[編輯] 參考
- C17 標準 (ISO/IEC 9899:2018)
- 7.29.6.2.1 mbsinit 函式 (p: 322)
- C11 標準 (ISO/IEC 9899:2011)
- 7.29.6.2.1 mbsinit 函式 (p: 441-442)
- C99 標準 (ISO/IEC 9899:1999)
- 7.24.6.2.1 mbsinit 函式 (p: 387-388)
[編輯] 另請參閱
(C95) |
迭代多位元組字串所需的轉換狀態資訊 (類) |
C++ 文件,關於 mbsinit
|