C program to find length of string using strlen function
using strlen() function, we can find the length of a string.
size_t strlen(char *);
Argument
strlen function takes an string(char *) argument.
strlen function return type
It will return an unsigned int which is the length of a given string.
string.h
strlen function is defined in string.h library.
Program
Example
#include<stdio.h> #include<string.h> int main() { char name[20]="Programming"; int length; length = strlen(name); printf("Length of %s = %d\n",name,length); return 0; }
Output
Length of Programming = 11
Incompatible implicit declaration of built-in function strlen
If we forget to add the string.h header file, we will get the following error.
"incompatible implicit declaration of built-in function strlen"
Solution
#include<string.h>
If we want to use strlen function in our source program, we should include string.h library.
Otherwise, it will throw the above warning message.