strlen() Function


The strlen() method counts and returns the number of character in a string. It takes the form :

int len = strlen(str1);

Where len is an integer variable, which receives the value of the length of the string. The argument may be a string constant. The ends at the first null character.


Sample Program

Program
#include <stdio.h>
#include <string.h>

int main() {
  char str1[50] = "abba";
  
  char str2[50];
  strcpy(str2,str1);
  int len=strlen(str1)-1;
  int count=0;
  for(int i=0;i<strlen(str1); i++)
  {
   if(str1[i]==str2[len])
    count=0;
   else
    ++count;
    len--;
  }
  if(count==0)
   printf("The string %s is a pallindrome",str1);
  else
   printf("The string %s is not a pallindrome",str1);
  return 0;
}