String Palindrome
String Palindrome
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;
}