mbrlen() function in C/C++


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);

Here,

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,

Example

 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 \n", len);
}

Output

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);

karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know

Updated on: 26-Jun-2020

108 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements