C program to calculate length of string and reverse the string without using string function.

#include<stdio.h>
int string_ln(char *p);
int main()
{
   char *str1;
   int k,l;
   printf("\n Enter a string:");
   scanf("%s",str1);
   l=string_ln(str1);
   printf("\n The length of %s is=%d",str1,l);
   printf("\n The reverse string is: ");
   for(k=l;k>=0;k--)
   {
     printf("%c",*(str1+k));
   }
   return 0;
}

int string_ln(char *p)
{
  int count = 0;
  while (*p!='\0')
{
  count++;
  p++;
}
return (count);
}

***Input && Output***




Post a Comment

0 Comments