Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- // Function prototypes
- void removeSpecial(char[]);
- void ignoreCase(char[], int);
- bool isPalindrome(char[],int);
- using namespace std;
- int main()
- {
- int const size = 80;
- char ch[size];
- bool flag;
- //user output
- cout << "Enter a line that might be a palindrome:" << endl;
- //user input character by character
- cin.getline(ch,size);
- cout << size << "since size shows up as 80, my isPalindrome will not work" << endl;
- removeSpecial(ch); // remove numbers 2154 and special characters @#$#$
- ignoreCase(ch, size); //ignores capital or non capital for comparison
- flag = isPalindrome(ch, size);
- /*
- if (isPalindrome(ch, size) == true)
- cout << "The string "<<ch<<" is a palindrome" << endl;
- else
- cout << "The string " << ch << " is NOT a palindrome"<<endl;
- */
- if (flag == true)
- cout << "The string " << ch << " is a palindrome" << endl;
- else
- cout << "The string " << ch << " is NOT a palindrome" << endl;
- return 0;
- }
- //perfectly working is efficient?
- void removeSpecial(char ch[])
- {
- int i, j;
- for (i = 0; ch[i] != '\0'; ++i)
- {
- while (! ( (ch[i] >= 'a' && ch[i] <= 'z') || (ch[i] >= 'A' && ch[i] <= 'Z' || ch[i] == '\0') ) )
- {
- for (j = i; ch[j] != '\0'; ++j)
- {
- ch[j] = ch[j + 1];
- }
- ch[j] = '\0';
- }
- }
- }
- bool isPalindrome(char ch[], int size)
- {
- bool flag = true;
- for (int i = 0; i < size; i++)
- {
- if (ch[i] != ch[size - 1])
- flag = false;
- else
- flag = true;
- }
- return flag;
- }
- //perfectly working
- void ignoreCase(char ch[],int size)
- {
- for (int n = 0; n<size && ch[n] != '\0'; n++)
- {
- if (ch[n] >= 'a'&&ch[n] <= 'z')
- ch[n] = ch[n] - 32;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement