Showing posts with label Palindrome in C Using Pointers. Show all posts
Showing posts with label Palindrome in C Using Pointers. Show all posts

Tuesday, November 27, 2018

Palindrome in C Using Pointers

A very simple program that will ask the user to give a string and then the program will check and determine if the given string is a palindrome or not using pointers in C.

I am currently accepting programming work, it projects, school 

programming projects, thesis and capstone projects, IT consulting 

work, computer tutorials, and web development work kindly contact me in the following email address for further details.  If you want to advertise on my website kindly contact me also in my email address also. Thank you.
My email address is the following jakerpomperada@gmail.com, jakerpomperada@aol.com, and jakerpomperada@yahoo.com.

My mobile number here in the Philippines is 09173084360.

My telephone number at home here in Bacolod City, Negros Occidental Philippines is  +63 (034) 4335675.

My personal website is http://www.jakerpomperada.com



Sample Program Output



Program Listing

#include <stdio.h>
 
void stringUpr(char *s);
void stringLwr(char *s);
 
int main()
{
char string[100];
char *ptr,*rev;
printf("\n\n");
printf("\tPalindrome Program ");
printf("\n\n");
printf("\tGive a String : ");
gets(string);
ptr=string;
stringUpr(ptr);
   while(*ptr!=NULL){
      ++ptr;
       }
      --ptr;
for(rev=string; ptr>=rev;){
   if(*ptr == *rev)
       {
        --ptr;
        rev++;
      }
    else
break;
    }

if(rev>ptr) {
   printf("\n\n");
   stringUpr(string);
   printf("\tThe given string %s is Palindrome.",string);
     }
 else {
   printf("\n\n");
   stringUpr(string);
   printf("\tThe given string %s is Not a Palindrome.",string);
}
  printf("\n\n");
  printf("\tEND OF PROGRAM");
  printf("\n\n");
}

void stringLwr(char *s)
{
    int i=0;
    while(s[i]!='\0')
    {
        if(s[i]>='A' && s[i]<='Z'){
            s[i]=s[i]+32;
        }
        ++i;
    }
}
 
void stringUpr(char *s)
{
    int i=0;
    while(s[i]!='\0')
    {
        if(s[i]>='a' && s[i]<='z'){
            s[i]=s[i]-32;
        }
        ++i;
    }
    
}