[Previous] [Contents] [Index] [Next]

mbstrnchr()

Search for a multibyte character in part of a string

Synopsis:

#include <photon/PhProto.h>

char * mbstrnchr( char const *string,
                  char const *mbchar, 
                  int num, 
                  int *count );

Description:

This function searches for a multibyte character in string that matches mbchar. The match must occur in the first num multibyte characters. If such a match is found, count (if provided) is set to the number of multibyte characters the matching character is from the beginning of the string. For example, if mbchar matches the first character in string, count is set to 0. If mbchar matches the second character in string, count is set to 1.

Returns:

A pointer to the beginning of the matching character within string. If no match is found within num characters, the function returns NULL and doesn't change count.

Examples:

Search the first 5 multibyte characters for a match to the provided UTF-8 character:

#include <Pt.h>
main()
  {
  char string[] = "Hello there: äîòéü found"; 
  char mbchar[] = "é";
  int count;
  char *p;

  if( p = mbstrchr( string, mbchar, 5, &count ) )
    printf( 
      "character found: character offset %d\n byte offset %d\n",
      count, p - string );
  else
    printf( " Not found " );
  }

Classification:

Photon

Safety:
Interrupt handler No
Signal handler Yes
Thread Yes

See also:

mbstrchr(), mbstrrchr()


[Previous] [Contents] [Index] [Next]