Strlen C



Arrays and Strings in Tamil

Strlen C

  • The strlen()  function returns the length of the given string. It doesn't count null character ‘\0‘.
 String Length

String Length

Sample Code

#include<stdio.h>
#include <string.h>
int main()
{
	char ch[20]={'K', 'a', 'a', 's', 'h', 'i', 'v', 'I', 'n', 'f', 'o', 't', 'e', 'c', 'h', '\0’};
	int l=strlen(ch);
	printf("Length of string is: %d",l);
	getch();
}
 Strlen

Learn C - C tutorial - Strlen - C examples - C programs

Output

Length of string is : 15

String Length Without Using Strlen() Function

Sample Code

#include <stdio.h>
void main()
{
    char string[50];
    int i, length = 0;
    printf("Enter a string \n");
    scanf("%s",string);
    for (i = 0; string[i] != '\0'; i++)
    {
        length++;
    }
    printf("The length of %s = %d\n", string, length);
    getch();
}
 String Length

Learn C - C tutorial - String Length Without Using Strlen Function- C examples - C programs

Output

Enter a string
kaashivinfotech
The length of kaashivinfotech = 15


Related Searches to Strlen C