by Dinesh Thakur Category: Function and Pointer

The length of a string is defined as the number of characters in it excluding the null terminator. The strlen function returns the length of a specified string. A typical call to this function takes the following form:

strlen (s)

For example, the program segment given below determines the length of a string using thestrlen function and prints it.

char str[] = "EVERYTHING is fair in LOVE and WAR";

printf("Length : %d\n", strlen(str));

Illustrates below strlen ( ).

#include <string.h>
void main ()
char S1[ ] = "ABCDE";
char S2 [] = "A";
char S3 [] = "Z";
char S4[] ="Dinesh,";
char S5[30];
char S6[] = "Good morning !";
printf("Length of string S1 = %d\n", strlen(S1));
printf("Length of string S6 = %d\n", strlen(S6));
printf("Comparison of S2 with S3 = %d\n", strcmp(S2,S3));
printf("Comparison of S3 with S2 = %d\n", strcmp(S3,S2));
printf ("Comparison of S3 with Z = %d\n", strcmp (S3,"Z"));
strcat (S4, S6);
printf("S4 = %s\n", S4);
strcpy(S5, S4);
printf("S5 = %s\n", S5);

How to use strlen () (String Length) work.

About Dinesh Thakur


Related Articles