1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Palindrome checking without using string.h

Discussion in 'C' started by pradeep, Feb 2, 2007.

  1. pradeep

    pradeep Team Leader

    Joined:
    Apr 4, 2005
    Messages:
    1,646
    Likes Received:
    86
    Trophy Points:
    0
    Occupation:
    Programmer
    Location:
    Kolkata, India
    Home Page:
    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:
    #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");
    
    }
    
     
  2. uma

    uma New Member

    Joined:
    Jan 31, 2007
    Messages:
    3
    Likes Received:
    0
    Trophy Points:
    0
    good in logical thiking
     
  3. karthick.RG.Rajan

    karthick.RG.Rajan New Member

    Joined:
    Dec 22, 2006
    Messages:
    2
    Likes Received:
    0
    Trophy Points:
    0

Share This Page