strlen, wcslen (Windows CE 5.0)
Developing an Application > Microsoft C Run-time Library for Windows CE > Run-time Library Reference
Get the length of a string.
size_tstrlen( const char *string);size_t wcslen( const wchar_t *string);
Parameters
- string
Null-terminated string.
Return Values
Each of these functions returns the number of characters in string, excluding the terminal NULL. No return value is reserved to indicate an error.
Remarks
These functions are supported by all versions of the C run-time libraries.
Each of these functions returns the number of characters in string, not including the terminating null character. wcslen is a wide-character version of strlen; the argument of wcslen is a wide-character string. wcslen and strlen behave identically otherwise.
The argument, string, must not be larger than the maximum number of bytes allowed in the buffer; otherwise, a buffer overrun can occur.
This can lead to a denial of service attack against the application if an access violation occurs, or in the worst case, allow an attacker to inject executable code into your process. Consider using an appropriate strsafe function.
For more information, see Safe String Functions.
The following table shows generic-text routine mappings for this function.
TCHAR.H Routine | _UNICODE Defined |
---|---|
_tcslen | wcslen |
_tcsclen | wcslen |
For more information about TCHAR.H routines, see Generic Text Mappings.
Example
Description
The following example finds the length of a string.
Code
#include <string.h>
#include <stdio.h>
#include <conio.h>
#include <dos.h>
void main( void )
{
char buffer[61] = "How long am I?";
size_t len;
len = strlen( buffer );
printf( "'%s' is %d characters long\n", buffer, len );
}
// Output
'How long am I?' is 14 characters long
Requirements
OS Versions: Windows CE 2.0 and later.
Header: stdio.h, string.h.
Link Library: coredll.dll.
See Also
Send Feedback on this topic to the authors