C program to find the length of a string without using the built-in function also check whether it is a palindrome or not

by Nideesh C on April 12, 2011 · 0 comments

in C Programming




/* C program to find the length of a string without using the built-in function also check whether it is a palindrome or not */

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

void main()
{
char string[25], revString[25]={‘\0′};
int  i,length = 0, flag = 0;

clrscr();
fflush(stdin);

printf(“Enter a string\n”);
gets(string);

for (i=0; string[i] != ‘\0′; i++) /*keep going through each */
{                                 /*character of the string */
length++;                     /*till its end */
}
printf(“The length of the string \’%s\’ = %d\n”, string, length);

for (i=length-1; i >= 0 ; i–)
{
revString[length-i-1] = string[i];
}
/*Compare the input string and its reverse. If both are equal
then the input string is palindrome. Otherwise it is
not a palindrome */

for (i=0; i < length ; i++)
{
if (revString[i] == string[i])
flag = 1;
else
flag = 0;

}

if (flag == 1)
printf (“%s is a palindrome\n”, string);
else
printf(“%s is not a palindrome\n”, string);
}

/*—————————————————-
Output
Enter a string
madam
The length of the string ‘madam’ = 5
madam is a palindrome

RUN2
Enter a string
good
The length of the string ‘good’ = 4
good is not a palindrome
———————————————————-*/

Not Satisfied ? Just search & get the result

Related Posts Plugin for WordPress, Blogger...
Be Sociable, Share!

Related posts:

  1. C program to read a string and check whether it is a palindrome or not (without using library functions). Output the given string along with suitable message.
  2. c program to find the length of a string without using the built-in function
  3. Sample – Program to enter a string and find its length.
  4. C program to reverse a given integer number and check whether it is a palindrome. Output the given numbers with suitable message
  5. C program to accept a string and a substring and check if the substring is present in the given string

Leave a Comment

Previous post:

Next post: