void clear char s This function takes a character pointer a
Solution
solution
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
char* reverse(char *k);
int compare(char *s,char *p);
int pallindrome(char *s);
void clear(char *s);
int main()
{
int k;
char *rever,*s1,*pallin;
char *string1,*string2;
printf(\"enter the two strings to compare and l string to compare:\");
//to read strings
string1 = malloc(256);
string2=malloc(256);
scanf(\"%255s\ \", string1); // Don\'t read more than 255 chars
scanf(\"%255s\ \", string2); // Don\'t read more than 255 chars
int i=compare(string1,string2);
if(i==0)
{
printf(\"two strings are equal %d\ \",i);
}else
printf(\"two string s are not equal %d\ \",i);
printf(\"enter the string to reverse\");
rever=malloc(256);
scanf(\"%s\",rever);
// Don\'t read more than 255 chars
s1=reverse(rever);
printf(\"the reversed string is %s\ \",s1);
pallin=malloc(256);
scanf(\"%255s\ \", pallin); // Don\'t read more than 255 chars
k=pallindrome(pallin);
if(k==0)
{
printf(\"the given string is pallindrome\ \");
}
else
{
printf(\"the given string is not a pallindrome\ \");
}
clear(pallin);
return 0;
}
int pallindrome(char *r)
{
int flag=0;
int i;
int lengt=strlen(r);
for ( i=0;i<lengt;i++) {
if(r[i]==r[lengt-i-1])
flag=flag+1;
}
if(flag==lengt)
return 0;
else
return 1;
}
void clear(char *s)
{
printf(\" the memory is free of string : %s \ \",s);
free(s);
}
char* reverse(char *s)
{
char *p;
p = malloc(256);
p=strrev(s);
return p;
}
int compare(char *s,char *s1)
{
int k=strcmp(s,s1);
return k;
}
output
enter the two strings to compare and l string to compare:
john
lisa
level
two string s are not equal -1
the reversed string is level
enter the string to test pallindrome
madam
the given string is pallindrome
the memory is free of string : madam


