Name

wmemchr, wmemcmp, wmemcpy, wmemmove, wmemset, wcscat, wcschr, wcscmp, wcscpy, wcscspn, wcslen, wcsncat, wcsncmp, wcsncpy, wcspbrk, wcsrchr, wcsspn, wcsstr, wcslcat,wcslcpy
- searches a wide character in a wide-character array

Library

libc.lib

Synopsis

  #include <wchar.h>
  wchar_t * wmemchr (const wchar_t *s, wchar_t c, size_t n);
  int wmemcmp (const wchar_t *s1, const wchar_t *s2, size_t n);
  wchar_t * wmemcpy (wchar_t * restrict s1, const wchar_t * restrict s2, size_t n);
  wchar_t * wmemmove (wchar_t *s1, const wchar_t *s2, size_t n);
  wchar_t * wmemset (wchar_t *s, wchar_t c, size_t n);
  wchar_t * wcscat (wchar_t * restrict s1, const wchar_t * restrict s2);
  wchar_t * wcschr (const wchar_t *s, wchar_t c);
  int wcscmp (const wchar_t *s1, const wchar_t *s2);
  wchar_t * wcscpy (wchar_t * restrict s1, const wchar_t * restrict s2);
  size_t wcscspn (const wchar_t *s1, const wchar_t *s2);
  size_t wcslcat (wchar_t *s1, const wchar_t *s2, size_t n);
  size_t wcslcpy (wchar_t *s1, const wchar_t *s2, size_t n);
  size_t wcslen (const wchar_t *s);
  wchar_t * wcsncat (wchar_t * restrict s1, const wchar_t * restrict s2, size_t n);
  int wcsncmp (const wchar_t *s1, const wchar_t * s2, size_t n);
  wchar_t * wcsncpy (wchar_t * restrict s1, const wchar_t * restrict s2, size_t n);
  wchar_t * wcspbrk (const wchar_t *s1, const wchar_t *s2);
  wchar_t * wcsrchr (const wchar_t *s, wchar_t c);
  size_t wcsspn (const wchar_t *s1, const wchar_t *s2);
  wchar_t * wcsstr (const wchar_t * restrict s1, const wchar_t * restrict s2);

Return values

wmemchr function returns a pointer to the first occurrence of c among the n wide characters starting at s , or NULL if c does not occur among these.

wcslcpy function returns wcslen(src); if retval >= siz, truncation occurred

wcslcat function returns wcslen(initial dst) + wcslen(src); if retval >= sizet,


Detailed description

The function wcslcat() appends a copy of the wide-character string pointed to by s2 (including the terminating null wide-character code) to the end of the wide-character string pointed to by s1. The initial wide-character code of string pointed to by s2 overwrites the null wide-character code at the end of s1. wcslcat() concatenates at most n-1 characters.

The function wcslcpy() copies the wide-character string pointed to by s2 (including the terminating null wide-character code) into the array pointed to by s1. It will copy at most n-1 characters.

The functions implement string manipulation operations over wide character strings. For a detailed description, refer to documents for the respective single-byte counterpart, such as memchr.


Examples

#include <wchar.h>
/* Illustrates how to use wmemcmp API */
int example_wmemcmp()
{  
  /* source wide character string */
  wchar_t *ws1 = L"test case",*ws2 = L"test case";
  int retval;
 /* comparing the 2 wide-char strings */
 retval = wmemcmp(ws1,ws2,500);
  /* checking for the return value */
  if(retval != 0)
   return 1;
  else
   return 0;
}

         

#include <wchar.h>
/* Illustrates how to use wmemcpy API */
int example_wmemcpy()
{  
  /* source wide character string */
  wchar_t ws1[50]=L"abcdefghij",*retval,ws2[50]=L"test";
  /* compare the strings */
  retval = wmemcpy(ws1,ws2,6);
  for(int i=0;i<6;i++)
  {
   if(retval[i] != ws2[i] || ws1[i] != ws2[i])
    return 1;
  }
  return 0;
}

         

#include <wchar.h>
/* Illustrates how to use wmemmove API */
int example_wmemmove()
{  
  /* source wide character string */
  wchar_t ws1[50]=L"abcdefghij",*retval,ws2[5] = L"abc";
  int i;
 
  /* move the contents of ws2 to ws1 */
  retval = wmemmove(ws1,ws2,3);
 /* compare the contents */
  for(i=0;i<3;i++)
  {
   if(ws1[i] != ws2[i])
     return 1;
  }
  return 0;
}

         

#include <wchar.h>
/* Illustrates how to use wmemset API */
int example_wmemset()
{  
  /* source wide character string */
  wchar_t ws1[50]=L"abcdefghij", *retval;
  int i;
  /* setting the wide-string ws1 */
  retval = wmemset(ws1,L’a’,7);
 /* comparing the contents */
  for(i=0;i<7;i++)
  {
   if(ws1[i] != L’a’)
     return 1;
  }
  return 0;
}

         

#include <wchar.h>
/* Illustrates how to use wmemchr API */
wchar_t *example_wmemchr(void)
{
 wchar_t *wcs = L"lmnopqr";
 size_t n;
 wchar_t wc = L’p’;
 wchar_t *res;
 /* number of wide characters to be searched */
 n = wcslen(wcs);
 /* search for the occurence of wchar wc in wide-char string wcs */
 res = wmemchr(wcs, wc, n);
 /* return the pointer */
 return(res);
}

         

#include <wchar.h>
/* Illustrates how to use wcslen API */
size_t example_wcslen(void)
{
 wchar_t *wcs = L"defqwert";
 size_t len;
 /* compute the length of the wide-char string */
 len = wcslen(wcs);
 /* return the length of the wide-char string */
 return (len);
}

         

#include <wchar.h>
/* Illustrates how to use wcscat API */
void example_wcscat(void)
{
 wchar_t wcs[100] = L"abc";
 wchar_t *wcs1 = L"def";
 wchar *res;
 /* concatenate the two strings */
 res = wcscat(wcs, wcs1);
 /* print the string that resulted from concatenation */
 wprintf(L"Output wide-char string is : %ls\n",res);
}

         

Output

abcdef

         

#include <wchar.h>
/* Illustrates how to use wcschr API */
int example_ wcschr ()
{  
  /* source wide character string */
 wchar_t search_char[15] = L"&&&&$%%%%%TTU";
 wchar_t *wstr;
 int i ;
 for(i = 0 ; search_char[i]; i++)
 {
   wstr = wcschr(L"", search_char[i]);
   if(wstr != NULL)
   {
    return -1;
   }
 }
 return 0;
}

         

int example_wcscmp()
{  
  /* source wide character string */
 wchar_t *wcs1 = "string1";
 wchar_t *wcs2 = "string2";
 int i ;
 i = wcscmp(wcs1, wcs2);
 if( i == 0)
  return -1;
 
 i = wcscmp(wcs1, L"string1");
 if(i != 0)
  return -1;
 
 return 0;
}

         

#include <wchar.h>
/* Illustrates how to use wcscpy API */
int example_wcscpy ()
{  
  /* source wide character string */
  wchar_t wcs1[15];
  wchar_t *res;
 
  /* copy the wide-char string into wcs1*/
  res = wcscpy(wcs1, L"Hello world");
 
  if(wcscmp(res, L"Hello world") != 0)
   return -1;
 
  return 0;
}

         

#include <wchar.h>
/* Illustrates how to use wcslcpy API */
int example_wcslcpy ()
{  
  /* source wide character string */
  wchar_t src[25] = L"Source";
  wchar_t dest[20]= L"Destination";
 
  /* copy the wide-char string into dest*/
 
        size_t t = wcslcpy(dest,src,4);
                
                if(wcscmp(dest,L"Sou")!=0)
    return -1;
 
  return 0;
}

         

#include <wchar.h>
/* Illustrates how to use wcslcat API */
int example_wcslcat ()
{  
  /* source wide character string */
  wchar_t src[25] = L"Source";
  wchar_t dest[20]= L"Destination";
 
  /* concate the wide-char string into dest*/
 
        size_t t = wcslcat(dest,src,14);
                
                if(wcscmp(dest,"DestinationSo")!=0)
    return -1;
 
  return 0;
}

         

#include <wchar.h>
/* Illustrates how to use wcscspnAPI */
int example_wcscspn ()
{  
  /* source wide character string */
  wchar_t wcs1[30] = L"[email protected]#$$";
  wchar_t *wcs2[20] = { L"abcdefghijkl",
     L":::?>_)+(|{>",
     L"~*(&IUIJJJ",
     L"1234567",
     L":::?>",
     L"1",
     L"as1sd2ds3ds48f5fd"
   };
  int i;
 
  for( i = 0; i < 3 ; i ++)
  {
   if( wcslen(wcs1) != wcscspn(wcs1,wcs2[i]))
     return -1;
  }
 
  return 0;
}

         

#include <wchar.h>
/* Illustrates how to use wcsncat API */
int example_wcsncat ()
{  
  /* source wide character string */
  wchar_t *res;
  wchar_t str[50];
 
  wcscpy(str, L"Hello");
  res = wcsncat(str,L" world",12);
 if(wcscmp(str, L"Hello world") != 0)
  return -1;
 else
  return 0;
}

         

#include <wchar.h>
/* Illustrates how to use wcsncmp API */
int example_wcsncmp()
{  
  /* source wide character string */
  wchar_t *wcs1 = L"Hello world";
  if(wcsncmp(wcs1,wcs1,wcslen(wcs1))) 
   return -1;
  else
   return 0;
}

         

#include <wchar.h>
/* Illustrates how to use wcsncpy API */
int example_wcsncpy ()
{  
  /* source wide character string */
  wchar_t wcs1[15] = L"Hello world";
  wchar_t *res;
  res = wcsncpy(wcs1,wcs1,wcslen(wcs1));
  if(wcscmp(res,wcs1))
  return -1;
  return 0;
}

         

#include <wchar.h>
/* Illustrates how to use wcspbrk API */
int example_wcspbrk ()
{  
  /* source wide character string */
 wchar_t *wcs = L"abcdefghijkl";
  wchar_t *res1 = wcspbrk(wcs, L"");
  if(res1 != NULL)
   return -1;
 
  return 0;
}

         

#include <wchar.h>
/* Illustrates how to use wcsrchr API */
int example_wcsrchr ()
{  
  /* source wide character string */
 wchar_t search_char[15] = L"&&&&$%%%%%TTU";
  wchar_t *wstr;
  int i ;
 
  for(i = 0 ; search_char[i]; i++)
  {
   wstr = wcsrchr(L"", search_char[i]);
   if(wstr != NULL)
   {
     return -1;
   }
  }
  return 0;
}

         

#include <wchar.h>
/* Illustrates how to use wcsspn API */
int example_wcsspn()
{  
  /* source wide character string */
 wchar_t wcs1[30] = L"[email protected]#$$";
 if(wcslen(wcs1) != wcsspn(wcs1,wcs1)) 
  return -1;
 return 0;
}

         

#include <wchar.h>
/* Illustrates how to use wcsstr API */
int example_wcsstr()
{  
  /* source wide character string */
 wchar_t *buf[20] = { L"fkhsdf%%38",L"rtti123123", };
 wchar_t *str  = wcsstr(buf[0],L"");
 wchar_t *str1 = wcsstr(buf[1],L"\0");
 if(wcscmp(str,buf[0]))
   return 1;
 if(wcscmp(str1,buf[1]))
   return 1
 return 0;
}

         

Security considerations

Please refer strcpy strcat



See also

memchr, memcmp, memcpy, memmove, memset, strcat, strchr, strcmp, strcpy, strcspn, strlen, strncat, strncmp, strncpy, strpbrk, strrchr, strspn, strstr

Feedback

For additional information or queries on this page send feedback

© 2005-2007 Nokia

Top