Export (0) Print
Expand All
Expand Minimize

_mbsnbcnt, _mbsnccnt, _strncnt, _wcsncnt

Return the number of characters or bytes within a supplied count.

size_t _mbsnbcnt(
   const unsigned char *string,
   size_t number 
);
size_t _mbsnccnt(
   const unsigned char *string,
   size_t number 
);

Parameters

string
String to be examined.
number
Number of characters or bytes to be examined in string.

Return Value

_mbsnbcnt returns the number of bytes found in the first number of multibyte characters of string. _mbsnccnt returns the number of characters found in the first number of bytes of string. If a NULL character is encountered before the examination of string has completed, they return the number of bytes or characters found before the NULL character. If string consists of fewer than number characters or bytes, they return the number of characters or bytes in the string. If number 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 number bytes of the single-byte string string. _wcsncnt returns the number of characters in the first number wide characters of the wide-character string string.

Remarks

_mbsnbcnt counts the number of bytes found in the first number of multibyte characters of string. _mbsnbcnt replaces mtob, and should be used in place of mtob.

_mbsnccnt counts the number of characters found in the first number of bytes of string. If _mbsnccnt encounters 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 replaces btom, and should be used in place of btom.

Generic-Text Routine Mappings

Routine _UNICODE & _MBCS not defined _MBCS defined _UNICODE defined
_tcsnbcnt (in TCHAR.H) _strncnt _mbsnbcnt _wcsncnt
_tcsnccnt (in TCHAR.H) _strncnt _mbsnbcnt  
_wcsncnt     _mbsnbcnt
_wcsncnt     _mbsnccnt

_strncnt is the single-byte–character string version and _wcsncnt is the wide-character–string version of these mapping routines. _strncnt and _wcsncnt are provided only for generic-text mapping and should not be used otherwise. For more information, see Using Generic-Text Mappings and see Generic-Text Mappings.

Requirements

Routine Required header Compatibility
_mbsnbcnt <mbstring.h> Win 98, Win Me, Win NT, Win 2000, Win XP
_mbsnccnt <mbstring.h> Win 98, Win Me, Win NT, Win 2000, Win XP
_strncnt <tchar.h> Win 98, Win Me, Win NT, Win 2000, Win XP
_wcsncnt <tchar.h> Win 98, Win Me, Win NT, Win 2000, Win XP

For additional compatibility information, see Compatibility in the Introduction.

Libraries

All versions of the C run-time libraries.

Example

// 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 %s multibyte characters\n", char_count );
   else
      printf( "The first 10 characters are single-byte.\n");
}

Output

The first 10 characters are single-byte.

See Also

String Manipulation Routines | _mbsnbcat | Run-Time Routines and .NET Framework Equivalents

Show:
© 2014 Microsoft