Palindrome String Check - C Programming



In this program we are going to check whether an entered string is a palindrome string or not.

1. First  of all we'll get a string from user.
2. Then we will copy the user entered string in another string so that the orginal string is not destroyed.
3. Then we will reverse the user entered string using string fuction strrev().
4. Then we'll compare the reversed string and the copy of orginal string for equality using string function strcmp().
5. Then we'll give an output based on the result produced by strcmp() function.

Here is the code:-

/*Palindrome String Check*/
#include<stdio.h>
#include<string.h>

int main(void){
    char a[80], b[80];
    printf("Enter a Line of Text: \n");
    fgets(a,sizeof(a),stdin);
    strcpy(b,a);
    strrev(a);
    if(strcmp(a,b) == 0){
        printf("'%s' is a palindrome string",b);
    } else {
        b[strlen(b)-1] = '\0';
        printf("'%s' is not a palindrome string",b);
    }
    return 0;
}

/*End of Program*/

Enjoy  :)

Comments



  1. Very informative article.Thank you author for posting this kind of article .



    http://www.wikitechy.com/view-article/string-copy-program-in-c-example-with-explanation



    Both are really good,
    Cheers,
    Venkat


    ReplyDelete

Post a Comment