Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I have this palindrome c++ function, it works with racecar and ana, but fails with avid diva. Maybe because of the whitespace in between the

I have this palindrome c++ function, it works with racecar and ana, but fails with avid diva. Maybe because of the whitespace in between the words. How do i fix it so that it works including on words with a space in between like" avid diva" ,we can not use the cstring library or any standard libraries? Below is my code

#include using namespace std;

int main(){ char string1[20]; int i, length; int flag = 0; cout << "Enter a string: "; cin >> string1; //gets char length int j = 0; while (string1[j] != '\0') { ++j; } length = j;

// palindrome function for(i=0;i < length ;i++){ if(string1[i] != string1[length-i-1]){ flag = 1; break; }}

if (flag) { cout << string1 << " is not a palindrome" << endl; } else { cout << string1 << " is a palindrome" << endl; } return 0; }

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Microsoft Visual Basic 2005 For Windows Mobile Web Office And Database Applications Comprehensive

Authors: Gary B. Shelly, Thomas J. Cashman, Corinne Hoisington

1st Edition

0619254823, 978-0619254827

More Books

Students also viewed these Databases questions