Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      mbsinit

      From cppreference.com
      <c‎ |string‎ |multibyte
       
       
       
       
      Defined in header<wchar.h>
      int mbsinit(constmbstate_t* ps);
      (since C95)

      Ifps is not a null pointer, thembsinit function determines whether the pointed-tombstate_t object describes the initial conversion state.

      Contents

      [edit]Notes

      Although a zero-initializedmbstate_t always represents the initial conversion state, there may be other values ofmbstate_t that also represent the initial conversion state.

      [edit]Parameters

      ps - pointer to the mbstate_t object to examine

      [edit]Return value

      0 ifps is not a null pointer and does not represent the initial conversion state, nonzero value otherwise.

      [edit]Example

      Run this code
      #include <locale.h>#include <string.h>#include <stdio.h>#include <wchar.h> int main(void){// allow mbrlen() to work with UTF-8 multibyte encodingsetlocale(LC_ALL,"en_US.utf8");// UTF-8 narrow multibyte encodingconstchar* str= u8"水";// or u8"\u6c34" or "\xe6\xb0\xb4"staticmbstate_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);}}

      Output:

      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

      [edit]References

      • C17 standard (ISO/IEC 9899:2018):
      • 7.29.6.2.1 The mbsinit function (p: 322)
      • C11 standard (ISO/IEC 9899:2011):
      • 7.29.6.2.1 The mbsinit function (p: 441-442)
      • C99 standard (ISO/IEC 9899:1999):
      • 7.24.6.2.1 The mbsinit function (p: 387-388)

      [edit]See also

      conversion state information necessary to iterate multibyte character strings
      (class)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=c/string/multibyte/mbsinit&oldid=133920"

      [8]ページ先頭

      ©2009-2025 Movatter.jp