The strlen function is used to determine the length of a given string. The method of use is as follows: include the string.h header file and declare a constant character pointer pointing to the given string. Call the strlen function, passing the character pointer as a parameter. The return value is stored in a variable of type size_t
How to use the strlen function in C language
strlen function Used to determine the length of a given string, it belongs to the string.h header file in the C standard library.
Syntax:
<code class="c">size_t strlen(const char *str);</code>
Parameters:
str
: To determine the length C string (const pointer). Return value:
strlen function returns the number of characters contained in str
(excluding the null character '\0').
Instructions:
To use the strlen function just follow these steps:
Example:
<code class="c">#include <stdio.h> #include <string.h> int main() { char str[] = "Hello, world!"; size_t length = strlen(str); printf("String length: %zu\n", length); return 0; }</code>
The above code will print the following output:
<code>String length: 13</code>
The above is the detailed content of How to use strlen function in c language. For more information, please follow other related articles on the PHP Chinese website!