strnlen_s, wcsnlen_s

From RAD Studio
Jump to: navigation, search

Go Up to string.h Index


Header File

string.h, stdio.h

Category

Memory and String Manipulation Routines

Prototype

size_t strnlen_s(const char *__s, size_t __maxlen);

size_t wcsnlen_s(const wchar_t *__s, size_t __maxlen);

Description

Determines the length of an user specified string.

strnlen_s calculated the size of the string that __s is pointing to.

Return Value

strnlen_s returns the number of characters the string pointed to by __s has. If __s is a null pointer, zero is returned. If the string is larger than __maxlen (meaning that there isn't a '\0' character before __maxlen), strlen_s returns __maxlen.

Example

#include <stdio.h>
#include <errno.h>
int main(void)
{
   char *myString = "This is my string.";
   printf_s("%s has: %d characters.\n", myString, strnlen_s(myString,50));
   return 0;
}

Portability

POSIX Win32 ANSI C ANSI C++

+