
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Watcom C Library Reference - <u>synopsis:</u>
[<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
Synopsis:
#include <mbstring.h>
size_t _mbsnccnt( const unsigned char *string, size_t n );
size_t _fmbsnccnt( const unsigned char __far *string,
size_t n );
#include <tchar.h>
size_t _strncnt( const char *string, size_t n );
size_t _wcsncnt( const wchar_t *string, size_t n ) {
Description:
The _mbsnccnt function counts the number of multibyte characters in the
first n bytes of the string string. If _mbsnccnt finds a null byte as
the second byte of a double-byte character, the first (lead) byte is not
included in the count.
Note: This function was called btom in earlier versions.
The _fmbsnccnt function is a data model independent form of the _strncnt
function that accepts far pointer arguments. It is most useful in mixed
memory model applications.
The header file <tchar.h> defines the generic-text routine _tcsnccnt.
This macro maps to _mbsnccnt if _MBCS has been defined, or to the
_wcsncnt macro if _UNICODE has been defined. Otherwise _tcsnccnt maps
to _strncnt. _strncnt and _wcsncnt are single-byte character string and
wide-character string versions of _mbsnccnt. The _strncnt and _wcsncnt
macros are provided only for this mapping and should not be used
otherwise.
The _strncnt function returns the number of characters (i.e., n) in the
first n bytes of the single-byte string string. The _wcsncnt function
returns the number of bytes (i.e., 2 * n) in the first n wide characters
of the wide-character string string.
Returns:
_strncnt returns the number of characters from the beginning of the
string to byte n. _wcsncnt returns the number of wide characters from
the beginning of the string to byte n. _mbsnccnt returns the number of
multibyte characters from the beginning of the string to byte n. If
these functions find a null character before byte n, they return the
number of characters before the null character. If the string consists
of fewer than n characters, these functions return the number of
characters in the string.
Example:
#include <stdio.h>
#include <mbctype.h>
#include <mbstring.h>
const unsigned char chars[] = {
' ',
'.',
'1',
'A',
0x81,0x40, /* double-byte space */
0x82,0x60, /* double-byte A */
0x82,0xA6, /* double-byte Hiragana */
0x83,0x42, /* double-byte Katakana */
0xA1, /* single-byte Katakana punctuation */
0xA6, /* single-byte Katakana alphabetic */
0xDF, /* single-byte Katakana alphabetic */
0xE0,0xA1, /* double-byte Kanji */
0x00
};
void main()
{
_setmbcp( 932 );
printf( "%d characters found\n",
_mbsnccnt( chars, 10 ) );
}
produces the following:
7 characters found
Classification:
WATCOM
Systems:
_mbsnccnt - DOS, Windows, Win386, Win32, OS/2 1.x(all), OS/2-32
_fmbsnccnt - DOS, Windows, Win386, Win32, OS/2 1.x(all), OS/2-32
_strncnt - MACRO
_wcsncnt - MACRO
See Also:
_mbsnbcat, _mbsnbcnt, _mbsnccnt
See Also:
Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson