Facebook Page Twitter Page LinkedIn Page
× C Standard Library


The C <wchar.h> wcslen() function returns the length of a wide string, which is, the number of characters in the wide string whose first element is pointed to by str (without including the terminating null character).

The behavior is undefined if there is no null character in the wide character array pointed to by str.

Syntax

size_t wcslen ( const wchar_t * str );

Parameters

str Specify pointer to the wide character array.

Return Value

Returns the length of a wide string.

Example:

The below example shows the usage of wcslen() function.

#include <stdio.h>
#include <wchar.h>
 
int main (){
  wchar_t str1[256] = L"Hello World!";
  wchar_t str2[256] = L"Programming is easy.";

  printf("str1 contains: %u characters.\n", wcslen(str1));
  printf("str2 contains: %u characters.\n", wcslen(str2));    
  return 0;
}

The output of the above code will be:

str1 contains: 12 characters.
str2 contains: 20 characters.

❮ C <wchar.h> Library