<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	
	>
<channel>
	<title>
	Comments on: C++ program to check if a sentence is a Palindrome or not	</title>
	<atom:link href="https://anas.pk/2011/04/01/c-program-to-check-if-a-sentence-is-a-palindrome-or-not/feed/" rel="self" type="application/rss+xml" />
	<link>https://anas.pk/2011/04/01/c-program-to-check-if-a-sentence-is-a-palindrome-or-not/</link>
	<description>API Integrations Expert &#124; Full-Stack web developer</description>
	<lastBuildDate>Tue, 29 Dec 2015 15:39:01 +0000</lastBuildDate>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9.4</generator>
	<item>
		<title>
		By: akon		</title>
		<link>https://anas.pk/2011/04/01/c-program-to-check-if-a-sentence-is-a-palindrome-or-not/#comment-13223</link>

		<dc:creator><![CDATA[akon]]></dc:creator>
		<pubDate>Tue, 29 Dec 2015 15:39:01 +0000</pubDate>
		<guid isPermaLink="false">http://anas.cz.cc/?p=223#comment-13223</guid>

					<description><![CDATA[Your code doesn&#039;t check for a palindrome sentence.
For example : race car]]></description>
			<content:encoded><![CDATA[<p>Your code doesn&#8217;t check for a palindrome sentence.<br />
For example : race car</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Daniel Lyons		</title>
		<link>https://anas.pk/2011/04/01/c-program-to-check-if-a-sentence-is-a-palindrome-or-not/#comment-51</link>

		<dc:creator><![CDATA[Daniel Lyons]]></dc:creator>
		<pubDate>Fri, 01 Apr 2011 05:58:15 +0000</pubDate>
		<guid isPermaLink="false">http://anas.cz.cc/?p=223#comment-51</guid>

					<description><![CDATA[Fun post! I&#039;m not a C++ programmer by any stretch of the imagination, but I came up with this:

#include
#include
#include

using namespace std;

bool is_palindrome(string line)
{
  deque characters;

  // push each alphabetic character onto the deque lowercased
  for (string::iterator i = line.begin(); i != line.end(); i++)
    if (isalpha(*i))
      characters.push_back(tolower(*i));

  while (!characters.empty())
  {
    // take something off the front
    char left = characters.front();
    characters.pop_front();

    // if we&#039;re out of things, then we&#039;re a palindrome because this is
    // the odd character that was left over.
    if (characters.empty())
      return true;

    // take something off the end
    char right = characters.back();
    characters.pop_back();

    // if the thing from the front and the thing from the end are the same,
    // we still may be a palindrome
    if (left != right)
      return false;
  }

  // if we make it here without more stuff on the end, we are a palindrome
  return characters.empty();
}

int main()
{
  string line;

  // read in a line
  cout &#060;&#060; &#034;Enter a line to check: &#034;;
  getline(cin, line);

  // so, is it a palindrome?
  bool palindrome = is_palindrome(line);

  // display different messages depending
  if (palindrome)
    cout &#060;&#060; &#034;Palindrome!&#034; &#060;&#060; endl;
  else
    cout &#060;&#060; &#034;Not a palindrome. :(&#034; &#060;&#060; endl;

  // make this state our UNIX return status, depending
  return (int)!palindrome;
}


This could probably be improved by just running a forward and a backward iterator in parallel instead of copying the string into a deque, but this made more sense to me.]]></description>
			<content:encoded><![CDATA[<p>Fun post! I&#8217;m not a C++ programmer by any stretch of the imagination, but I came up with this:</p>
<p>#include<br />
#include<br />
#include</p>
<p>using namespace std;</p>
<p>bool is_palindrome(string line)<br />
{<br />
  deque characters;</p>
<p>  // push each alphabetic character onto the deque lowercased<br />
  for (string::iterator i = line.begin(); i != line.end(); i++)<br />
    if (isalpha(*i))<br />
      characters.push_back(tolower(*i));</p>
<p>  while (!characters.empty())<br />
  {<br />
    // take something off the front<br />
    char left = characters.front();<br />
    characters.pop_front();</p>
<p>    // if we&#8217;re out of things, then we&#8217;re a palindrome because this is<br />
    // the odd character that was left over.<br />
    if (characters.empty())<br />
      return true;</p>
<p>    // take something off the end<br />
    char right = characters.back();<br />
    characters.pop_back();</p>
<p>    // if the thing from the front and the thing from the end are the same,<br />
    // we still may be a palindrome<br />
    if (left != right)<br />
      return false;<br />
  }</p>
<p>  // if we make it here without more stuff on the end, we are a palindrome<br />
  return characters.empty();<br />
}</p>
<p>int main()<br />
{<br />
  string line;</p>
<p>  // read in a line<br />
  cout &lt;&lt; &quot;Enter a line to check: &quot;;<br />
  getline(cin, line);</p>
<p>  // so, is it a palindrome?<br />
  bool palindrome = is_palindrome(line);</p>
<p>  // display different messages depending<br />
  if (palindrome)<br />
    cout &lt;&lt; &quot;Palindrome!&quot; &lt;&lt; endl;<br />
  else<br />
    cout &lt;&lt; &quot;Not a palindrome. :(&quot; &lt;&lt; endl;</p>
<p>  // make this state our UNIX return status, depending<br />
  return (int)!palindrome;<br />
}</p>
<p>This could probably be improved by just running a forward and a backward iterator in parallel instead of copying the string into a deque, but this made more sense to me.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Jacob		</title>
		<link>https://anas.pk/2011/04/01/c-program-to-check-if-a-sentence-is-a-palindrome-or-not/#comment-50</link>

		<dc:creator><![CDATA[Jacob]]></dc:creator>
		<pubDate>Fri, 01 Apr 2011 00:27:10 +0000</pubDate>
		<guid isPermaLink="false">http://anas.cz.cc/?p=223#comment-50</guid>

					<description><![CDATA[Use the string class (#include ).  You can do an infinite length input, don&#039;t need to calculate the length of it (it is a member function call), and you can access it like a char array.

Also, ! the if statement when checking for tolower, that way you can put the cout not a palindrome logic in there without an if-else statement, only need an if statement.]]></description>
			<content:encoded><![CDATA[<p>Use the string class (#include ).  You can do an infinite length input, don&#8217;t need to calculate the length of it (it is a member function call), and you can access it like a char array.</p>
<p>Also, ! the if statement when checking for tolower, that way you can put the cout not a palindrome logic in there without an if-else statement, only need an if statement.</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Anthony		</title>
		<link>https://anas.pk/2011/04/01/c-program-to-check-if-a-sentence-is-a-palindrome-or-not/#comment-49</link>

		<dc:creator><![CDATA[Anthony]]></dc:creator>
		<pubDate>Thu, 31 Mar 2011 23:55:07 +0000</pubDate>
		<guid isPermaLink="false">http://anas.cz.cc/?p=223#comment-49</guid>

					<description><![CDATA[Little bug on my program above, I actually had this in a function so the cout statements were return statements (originally true and false).  So the code doesn&#039;t precisely work as I just posted, (it will post NOT A PALINDROME and PALINDROME HELL YEAH for failures and PALINDROME HELL YEAH for successes)]]></description>
			<content:encoded><![CDATA[<p>Little bug on my program above, I actually had this in a function so the cout statements were return statements (originally true and false).  So the code doesn&#8217;t precisely work as I just posted, (it will post NOT A PALINDROME and PALINDROME HELL YEAH for failures and PALINDROME HELL YEAH for successes)</p>
]]></content:encoded>
		
			</item>
		<item>
		<title>
		By: Anthony		</title>
		<link>https://anas.pk/2011/04/01/c-program-to-check-if-a-sentence-is-a-palindrome-or-not/#comment-48</link>

		<dc:creator><![CDATA[Anthony]]></dc:creator>
		<pubDate>Thu, 31 Mar 2011 23:51:53 +0000</pubDate>
		<guid isPermaLink="false">http://anas.cz.cc/?p=223#comment-48</guid>

					<description><![CDATA[I tried to write my own... I noted that you were going for case insensitive so I included this as well, though it would be simpler without it...

This one doesn&#039;t care about the length beyond the fact that the character array is given a limit on length, and calculates it as it inputs instead of needing to input it and then reiterate to calculate the length.

Also I decided to go with pointers over the array notation.

Though this solution could be wrong, I&#039;m only in an intro C++ course and saw this post on reddit.


#include
using namespace std;

int main()
{
    // Wouldn&#039;t this be an easier way to input the characters?

    const int SIZE = 50;
    char* charArray = new char[SIZE];
    char* tempStartPointer = charArray;
    char* tempEndPointer = charArray;

    int length = 0;
    char c = cin.get();
    while(c != &#039;n&#039; &#038;&#038; length &#060; SIZE - 1) // SIZE  1 for null char
    {
        *(tempEndPointer++) = c;
        length++;
        c = cin.get();
    }

    // for debugging give it the extra null char
    *tempEndPointer = &#039;&#039;;

    // move tempEndPointer back one so it is at the end of the string
    tempEndPointer--;

    while(tempStartPointer &#060; tempEndPointer)
    {
        if(!isalpha(*tempStartPointer))
        {
            tempStartPointer++;
            continue;
        }

        if(!isalpha(*tempEndPointer))
        {
            tempEndPointer--;
            continue;
        }

        if(toupper(*tempStartPointer++) != toupper(*tempEndPointer--))
        {
            cout &#060;&#060; &#034;NOT A PALINDROME&#034;;
            break;
        }
    }

    cout &#060;&#060; &#034;PALINDROME HELL YEAH&#034;;

    delete[] charArray;

    return 0;
}]]></description>
			<content:encoded><![CDATA[<p>I tried to write my own&#8230; I noted that you were going for case insensitive so I included this as well, though it would be simpler without it&#8230;</p>
<p>This one doesn&#8217;t care about the length beyond the fact that the character array is given a limit on length, and calculates it as it inputs instead of needing to input it and then reiterate to calculate the length.</p>
<p>Also I decided to go with pointers over the array notation.</p>
<p>Though this solution could be wrong, I&#8217;m only in an intro C++ course and saw this post on reddit.</p>
<p>#include<br />
using namespace std;</p>
<p>int main()<br />
{<br />
    // Wouldn&#8217;t this be an easier way to input the characters?</p>
<p>    const int SIZE = 50;<br />
    char* charArray = new char[SIZE];<br />
    char* tempStartPointer = charArray;<br />
    char* tempEndPointer = charArray;</p>
<p>    int length = 0;<br />
    char c = cin.get();<br />
    while(c != &#8216;n&#8217; &amp;&amp; length &lt; SIZE &#8211; 1) // SIZE  1 for null char<br />
    {<br />
        *(tempEndPointer++) = c;<br />
        length++;<br />
        c = cin.get();<br />
    }</p>
<p>    // for debugging give it the extra null char<br />
    *tempEndPointer = &#039;&#039;;</p>
<p>    // move tempEndPointer back one so it is at the end of the string<br />
    tempEndPointer&#8211;;</p>
<p>    while(tempStartPointer &lt; tempEndPointer)<br />
    {<br />
        if(!isalpha(*tempStartPointer))<br />
        {<br />
            tempStartPointer++;<br />
            continue;<br />
        }</p>
<p>        if(!isalpha(*tempEndPointer))<br />
        {<br />
            tempEndPointer&#8211;;<br />
            continue;<br />
        }</p>
<p>        if(toupper(*tempStartPointer++) != toupper(*tempEndPointer&#8211;))<br />
        {<br />
            cout &lt;&lt; &quot;NOT A PALINDROME&quot;;<br />
            break;<br />
        }<br />
    }</p>
<p>    cout &lt;&lt; &quot;PALINDROME HELL YEAH&quot;;</p>
<p>    delete[] charArray;</p>
<p>    return 0;<br />
}</p>
]]></content:encoded>
		
			</item>
	</channel>
</rss>
