mbrlen() function in C/C++ Last Updated : 05 Sep, 2018 Summarize Comments Improve Suggest changes Share Like Article Like Report The mbrlen() function in C/C++ determines the size in bytes, of the remainder of the multibyte character whose first byte is pointed to by str, given the current conversion state ps. The behavior of this function depends on the LC_CTYPE category of the selected C locale. Syntax: size_t mbrlen( const char* str, size_t n, mbstate_t* ps) Parameters: The function accepts three mandatory parameters which are described below: str: specifies the pointer to the first byte of multibyte string to examine n: specifies the mAximum number of bytes in s to examine ps: specifies the pointer to mbstate_t object that defines a conversion state Return value : The function returns four value as below: the number of bytes which complete a valid multibyte character -1 if encoding error occurs 0 if s points to null character -2 if the next n bytes are part of a possibly valid multibyte character, which is still incomplete after examining all n bytes Below programs illustrate the above function: Program 1 : CPP // C++ program to illustrate // mbrlen() function #include <bits/stdc++.h> using namespace std; // Function to find the size of // the multibyte character void check_(const char* str, size_t n) { // Multibyte conversion state mbstate_t ps = mbstate_t(); // number of byte to be saved in returnV int returnV = mbrlen(str, n, &ps); if (returnV == -2) cout << "Next " << n << " byte(s) doesn't" << " represent a complete" << " multibyte character" << endl; else if (returnV == -1) cout << "Next " << n << " byte(s) doesn't " << "represent a valid multibyte character" << endl; else cout << "Next " << n << " byte(s) of " << str << "holds " << returnV << " byte" << " multibyte character" << endl; } // Driver code int main() { setlocale(LC_ALL, "en_US.utf8"); char str[] = "\u10000b5"; // test for first 1 byte check_(str, 1); // test for first 6 byte check_(str, 6); return 0; } Output: Next 1 byte(s) doesn't represent a complete multibyte character Next 6 byte(s) of á??0b5holds 3 byte multibyte character Program 2: CPP // C++ program to illustrate // mbrlen() function // with empty string #include <bits/stdc++.h> using namespace std; // Function to find the size of the multibyte character void check_(const char* str, size_t n) { // Multibyte conversion state mbstate_t ps = mbstate_t(); // number of byte to be saved in returnV int returnV = mbrlen(str, n, &ps); if (returnV == -2) cout << "Next " << n << " byte(s) doesn't" << " represent a complete" << " multibyte character" << endl; else if (returnV == -1) cout << "Next " << n << " byte(s) doesn't " << "represent a valid multibyte character" << endl; else cout << "Next " << n << " byte(s) of " << str << "holds " << returnV << " byte" << " multibyte character" << endl; } // Driver code int main() { setlocale(LC_ALL, "en_US.utf8"); char str[] = ""; // test for first 1 byte check_(str, 1); // test for first 3 byte check_(str, 3); return 0; } Output: Next 1 byte(s) of holds 0 byte multibyte character Next 3 byte(s) of holds 0 byte multibyte character Comment More infoAdvertise with us Next Article strlen() function in c A AmanSrivastava1 Follow Improve Article Tags : C++ CPP-Functions C-Library Practice Tags : CPP Similar Reads strlen() function in c The strlen() function in C calculates the length of a given string. The strlen() function is defined in string.h header file. It doesn't count the null character '\0'. Syntax of C strlen() The syntax of strlen() function in C is as follows: size_t strlen(const char* str);Parameters The strlen() func 1 min read mbsinit() Function in C/C++ The mbsinit() is an inbuilt function in C++ which is used to check whether ps(passed as a parameter to this function) points to a mbstate_t object that describes an initial conversion state. This function returns non-zero for any mbstate_t object representing an initial state, or if ps is a null poi 3 min read mbrtowc() function in C/C++ The mbrtowc() function in C/C++ converts multibyte sequence to wide characters. This function returns the length in bytes of a multibyte character. The multibyte character pointed by s is converted to a value of type wchar_t and stored at the location pointed by pwc. If s points to a null character, 3 min read iswblank() function in C/C++ The iswblank() is a built-in function in C/C++ which checks if the given wide character is a blank character or not. It is defined within the cwctype header file of C++. Syntax: int iswblank(ch) Parameter: The function accepts a single mandatory parameter ch which specifies the wide character which 2 min read strcspn() function in C/C++ The strcspn() function in C/C++ takes two string as input, string_1 and string_2 as it's argument and searches string_1 by traversing for any characters that is present in string_2 . The function will return the length of string_1 if none of the characters of string_2 are found in string_1 . This fu 2 min read strol() function in C++ The strtol() function in C++ interprets the contents of a string as an integral number of the specified base and return its value as a long int.This function also sets an end pointer that points to the first character after the last valid numeric character of the string, if there is no such characte 3 min read Like