I can not get my C++ program to work right. It is supposed
to tell if a word is a palindrome or not, but it only tells
thet the word is not a palindrome. And I can't fix it.



I can not get my C++ program to work right. It is supposed to tell if a word is a palindrome or not..

Answer / sam

#include <iostream>
using namespace std;

int pali (char word[30]);
int main () {

char word[30];
char ans[5];
int answer;

cout << "Please enter a word (in all lowercase letters)"
<< endl;
cin.getline(word,30);

answer = pali(word);
if (answer == 1){
strcpy(ans,"a");
}
else{
strcpy(ans,"not a");
}
cout << " The word you entered was " << ans << "
palidrome" << endl;

}

int pali(char word[30]) {

char flip[30];
int length;
length = strlen(word);

for (int w = length-1, f = 0 ; w > -1; w--, f++) {
flip[f] = word[w];
}
strcmp(word,flip);
if (word == flip) {
return 1;
}
else {
return 0;
}
}

Is This Answer Correct ?    2 Yes 2 No

Post New Answer

More C C++ Errors Interview Questions

what is macro in c? Difference between single linked list & double linked list what is fifo & lifo? what is stack & queue?

2 Answers   TCS,


how to convert decimal to hexadecimal without using arrays just loops

2 Answers  


write a profram for selection sort whats the error in it?

2 Answers  


what is the large sustained error signal that eventually cause the controller output to drive to its limit

1 Answers   TCS,


what is exceptions?

5 Answers   HCL, Wipro,






A sample program using data structure? what is file handling?

0 Answers   TCS,


Given an int variable n that has already been declared and initialized to a positive value, and another int variable j that has already been declared, use a do...while loop to print a single line consisting of n asterisks. Thus if n contains 5, five asterisks will be printed. Use no variables other than n and j .

2 Answers  


Write a C program to enter 10 integer numbers through one variable and count how many of them are even using while loop ?

2 Answers  


Write a c-programe that input one number of four digits and find digits sum?

2 Answers  


What is the out put of this programme? int a,b,c,d; printf("Enter Number!\n"); scanf("%d",&a); while(a=!0) { printf("Enter numbers/n"); scanf("%d%d%d",&b,&c,&d); a=a*b*c*d; } printf("thanks!"); getche(); Entering numbers are a=1,b=2,c=3,d=4 b=3,c=4,d=-5 b=3,c=4,d=0

5 Answers   TCS,


write the value of x and y after execution of the statements: int x=19,y; y=x++ + ++x; x++; y++;

0 Answers  


what is meant by linking error? how can i solve it? if there is a linking error " unable to open file 'cos.obj'? then what should i do?

1 Answers  


Categories