Quantcast
Channel: CodeChef Discuss - latest questions
Viewing all articles
Browse latest Browse all 39796

Why is my code not working?

$
0
0

QUES=> Write a recursive function using pointers to determine whether a string is palindrome, Capitalization and spacing are ignored. Test your with the following two palindromes and at least one case that is not a palindrome.

CODE=>

include<stdio.h>

include<conio.h>

include<string.h>

void rev(char a,int l);
void comp(char
b,char a);
void main()
{
int l;
char x[20];
clrscr();
printf("ENTER THE STRING:");
gets(x);
l=strlen(x);
//printf("%d",l);
rev(&x[0],l-1);
}
void rev(char
a,int l)
{
int i;
char b;
if(l==0)
{
(b)=(a);
//for(i=0;i<l;i++)<br> //{
printf("%c",
(b));
//}
comp(b,a);
}
else
{
(b+l)=(a+l);
//for(i=0;i<l;i++)<br> //{
printf("%c",*(b+l));
//}

rev(a,l-1);
}
}
void comp(char b,char a)
{
int l1=strlen(b),l2=strlen(a),count=0;
int i,j;
printf("%d %d",l1,l2);
for(i=0;i<l2;i++)<br> {
if((b+i)!=(a+l1-i-1))
{
count++;
break;
}
}
if(count==0)
printf("STRING IS PALINDROME");
else
printf("STRING IS NOT PALINDROME");
getch();
}


Viewing all articles
Browse latest Browse all 39796

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>