Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/articles/c-tutorials/)
-   -   Palindrome checking without using string.h (http://www.go4expert.com/articles/palindrome-checking-using-stringh-t2834/)

pradeep 3Feb2007 00:26

Palindrome checking without using string.h
 
One of my friends, who is learning to program in C, asked me about how to write a program which checks an inputed string is a palindrome or not, without using the header file string.h

So here's the solution.

Code: C

#include <stdio.h>

void main(void)
{
    char str[50];
    int len=0,i=0,j,flag=1;
   
    printf("Enter a string: ");
    gets(str);
   
    while(str[i++]!='\0')
        len++;

    for(i=0,j=(len-1);i<len/2;i++,j--)
    {
        if(str[j]!=str[i])
        {
            flag=0;
            break;
        }
    }
       
    if(flag==1)
        printf("String is a palindrome");
    else
        printf("String is not a palindrome");

}


uma 3Feb2007 10:48

Re: Palindrome checking without using string.h
 
good in logical thiking

karthick.RG.Rajan 25Mar2007 23:41

Re: Palindrome checking without using string.h
 
Superb Sir


All times are GMT +5.5. The time now is 17:43.