mbrlen() function in C/C++

CC++Server Side Programming

The function mbrlen() is used to get the length of multibyte character. It returns the size of multibyte character pointed by the pointer.

Here is the syntax of mbrlen() in C language,

size_t mbrlen(const char* pointer, size_t size, mbstate_t* state);


pointer − Pointer to the first byte of multibyte character.

size − Number of bytes to check.

state − Pointer to the object of mbstate_t

Here is an example of mbrlen() in C language,


 Live Demo

#include <stdio.h>
#include <stdlib.h>
#include <wchar.h>
int main(void) {
   char a[] = "s";
   mbstate_t s;
   int len;
   len = mbrlen(a, 5, &s);
   printf("Length of multibyte character : %d 
", len); }


Length of multibyte character : 1

In the above program, we are calculating the length of multibyte character in bytes by using mbrlen() function.

char a[] = "s";
mbstate_t s;
int len;
len = mbrlen(a, 5, &s);
Updated on 26-Jun-2020 08:19:06