_strncnt, _wcsncnt, _mbsnbcnt, _mbsnbcnt_l, _mbsnccnt, _mbsnccnt_l

 

For the latest documentation on Visual Studio 2017, see Visual Studio 2017 Documentation.

For the latest documentation on Visual Studio 2017, see _strncnt, _wcsncnt, _mbsnbcnt, _mbsnbcnt_l, _mbsnccnt, _mbsnccnt_l on docs.microsoft.com. Returns the number of characters or bytes within a specified count.

System_CAPS_ICON_important.jpg Important

_mbsnbcnt, _mbsnbcnt_l, _mbsnccnt, and _mbsnccnt_l cannot be used in applications that execute in the Windows Runtime. For more information, see CRT functions not supported with /ZW.

size_t _strncnt(  
   const char *str,  
   size_t count  
);  
size_t _wcsncnt(  
   const wchar_t *str,  
   size_t count  
);  
size_t _mbsnbcnt(  
   const unsigned char *str,  
   size_t count   
);  
size_t _mbsnbcnt_l(  
   const unsigned char *str,  
   size_t count,  
   _locale_t locale  
);  
size_t _mbsnccnt(  
   const unsigned char *str,  
   size_t count  
);  
size_t _mbsnccnt_l(  
   const unsigned char *str,  
   size_t count,  
   _locale_t locale  
);  
  

Parameters

str
String to be examined.

count
Number of characters or bytes to be examined in str.

locale
Locale to use.

_mbsnbcnt and _mbsnbcnt_l return the number of bytes found in the first count of multibyte characters of str. _mbsnccnt and _mbsnccnt_l return the number of characters found in the first count of bytes of str. If a NULL character is encountered before the examination of str has completed, they return the number of bytes or characters found before the NULL character. If str consists of fewer than count characters or bytes, they return the number of characters or bytes in the string. If count is less than zero, they return 0. In previous versions, these functions had a return value of type int rather than size_t.

_strncnt returns the number of characters in the first count bytes of the single-byte string str. _wcsncnt returns the number of characters in the first count wide characters of the wide-character string str.

_mbsnbcnt and _mbsnbcnt_l count the number of bytes found in the first count of multibyte characters of str. _mbsnbcnt and _mbsnbcnt_l replace mtob and should be used in place of mtob.

_mbsnccnt and _mbsnccnt_l count the number of characters found in the first count of bytes of str. If _mbsnccnt and _mbsnccnt_l encounter a NULL in the second byte of a double-byte character, the first byte is also considered to be NULL and is not included in the returned count value. _mbsnccnt and _mbsnccnt_l replace btom and should be used in place of btom.

If str is a null pointer or is count is 0, these functions invoke the invalid parameter handler as described in Parameter Validation, errno is set to EINVAL, and the function returns 0.

The output value is affected by the setting of the LC_CTYPE category setting of the locale; see setlocale for more information. The versions of these functions without the _l suffix use the current locale for this locale-dependent behavior; the versions with the _l suffix are identical except that they use the locale parameter passed in instead. For more information, see Locale.

Generic-Text Routine Mappings

Routine_UNICODE and _MBCS not defined_MBCS defined_UNICODE defined
_tcsnbcnt_strncnt_mbsnbcnt_wcsncnt
_tcsnccnt_strncnt_mbsnbcntn/a
_wcsncntn/an/a_mbsnbcnt
_wcsncntn/an/a_mbsnccnt
n/an/a_mbsnbcnt_l_mbsnccnt_l
RoutineRequired header
_mbsnbcnt<mbstring.h>
_mbsnbcnt_l<mbstring.h>
_mbsnccnt<mbstring.h>
_mbsnccnt_l<mbstring.h>
_strncnt<tchar.h>
_wcsncnt<tchar.h>

For more compatibility information, see Compatibility.

// crt_mbsnbcnt.c  
  
#include  <mbstring.h>  
#include  <stdio.h>  
  
int main( void )  
{  
   unsigned char str[] = "This is a multibyte-character string.";  
   unsigned int char_count, byte_count;  
   char_count = _mbsnccnt( str, 10 );  
   byte_count = _mbsnbcnt( str, 10 );  
   if ( byte_count - char_count )  
      printf( "The first 10 characters contain %d multibyte characters\n", char_count );  
   else  
      printf( "The first 10 characters are single-byte.\n");  
}  

The first 10 characters are single-byte.  

Not applicable. To call the standard C function, use PInvoke. For more information, see Platform Invoke Examples.

String Manipulation
Locale
Interpretation of Multibyte-Character Sequences
_mbsnbcat, _mbsnbcat_l

Show: