0% found this document useful (0 votes)
15 views2 pages

String Palindrome

Uploaded by

Chetan Cherry
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views2 pages

String Palindrome

Uploaded by

Chetan Cherry
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

#include <stdio.

h>
#include <string.h>
void my_strcpy(char *d,char *s);
void my_strrev(char *s);
int my_strcmp(char *f,char*s);
int main()
{
char s[30], d[30];
printf("Enter string1:\n");
scanf("%[^\n]s",s);
my_strcpy(d, s);
my_strrev(d);
if (my_strcmp(s,d) == 0)
printf("The string is a palindrome.\n");
else
printf("The string is not a palindrome.\n");

return 0;
}
void my_strrev(char *s)
{
char ch;
char *p;
p=s;
while(*p)
{
p++;
}
p=p-1;
while(s<p)
{
ch=*s;
*s=*p;
*p=ch;
s++;
p--;
}

}
void my_strcpy(char *d,char *s)
{
while(*s)
{
*d=*s;
s++;
d++;
}
*d='\0';
}
int my_strcmp(char *f,char*s)
{
while(*f)
{
if(*f!=*s)
{
break;
}
f++;
s++;
}
if(*f==*s)
return 0;
else if(*f>*s)
return 1;
else
return -1;
}

You might also like