The strlen() function calculates the length of a given string.
Syntax:
Output:
Syntax:
int n = strlen(const char *str);
The function takes a single argument, i.e, the string variable whose length is to be found, and returns the length of the string passed.
The strlen() function is defined in <string.h> header file.
1A_Pro18: W.A.P to perform strlen() function on string.
#include<stdio.h>
#include<string.h>
void main()
{
char a[20]="Program";
char b[20]={'P','r','o','g','r','a','m','\0'};
char c[20];
clrscr();
The function takes a single argument, i.e, the string variable whose length is to be found, and returns the length of the string passed.
The strlen() function is defined in <string.h> header file.
1A_Pro18: W.A.P to perform strlen() function on string.
#include<stdio.h>
#include<string.h>
void main()
{
char a[20]="Program";
char b[20]={'P','r','o','g','r','a','m','\0'};
char c[20];
clrscr();
printf("Enter string: ");
gets(c);
gets(c);
printf("Length of string a = %d \n",strlen(a));
//calculates the length of string before null charcter.
printf("Length of string b = %d \n",strlen(b));
printf("Length of string c = %d \n",strlen(c));
getch();
}
//calculates the length of string before null charcter.
printf("Length of string b = %d \n",strlen(b));
printf("Length of string c = %d \n",strlen(c));
getch();
}
Output: