- strlen( ) function in C gives the length of the given string. Syntax for strlen( ) function is given below.
size_t strlen ( const char * str );
- strlen( ) function counts the number of characters in a given string and returns the integer value.
- It stops counting the character when null character is found. Because, null character indicates the end of the string in C.
Example program for strlen() function in C:
- In below example program, length of the string “computerscience” is determined by strlen( ) function as below. Length of this string 17 is displayed as output.
#include <stdio.h> #include <string.h> int main( ) { int len; char array[20]="computerscience" ; len = strlen(array) ; printf ( "\string length = %d \n" , len ) ; return 0; }
Output:
string length = 15
|
0 comments:
Post a Comment