C++ :: Program That Checks Whether A String Is Palindrome

Apr 27, 2014

Write a program that checks whether a string is a palindrome. A palindrome is a word, phrase, orsequence that can be read the same backward and forward.

Code:
#include<iostream>
#include<string>
using namespace std;
int main(){

[Code] .....

View 2 Replies


ADVERTISEMENT

C++ :: Program To Check Whether Or Not A String Is Palindrome

May 20, 2013

So I've been tasked with creating a program that checks to see whether or not a string is a palindrome. It has to remove whitespace, punctuation, and capitalization for obvious reasons. Getting some errors which I'm not sure how to correct.

On an unrelated note, while programming in the console, my cursor has turned into a gray box and replaces characters when typing, instead of pushing them forward, etc. How do I return it to normal?

#include <iostream>
#include <string>
#include <iomanip>
using namespace std;
bool isPalin(string& palin);
string cleanUp(string& palin);

[Code] .....

View 7 Replies View Related

C :: Checking Whether A String Is Palindrome Or Not

Nov 4, 2013

Everything seems to be correct from my perspective. heres the program: Code: /*c program to check whether a string is palindrome or not*/

#include<stdio.h>
#include<string.h>

int main(void) {
char str[30];
int i,j,flag=0;

[Code] .....

View 1 Replies View Related

C++ :: Identifier String Value Is Palindrome Or Not

Feb 9, 2013

here is my code, the issue is its not determine if the value is a palindrome or not.

// unit 5b.cpp : Defines the entry point for the console application.
//
// How to read a file
// identify the string if its a palindrome or not
//

#include "stdafx.h"
#include <iostream>
#include <cctype>
#include <fstream>

[Code] .....

View 1 Replies View Related

C++ :: Check A String To Be Palindrome

Apr 23, 2014

I am trying to check a string to be a palindrome. I have tried using for loop but I am looking for most efficient way.

View 5 Replies View Related

C/C++ :: Program That Opens Text File And Checks Usernames Listed In Text Files?

Jun 5, 2014

I want to make a program that opens a text file and checks the usernames listed in the text files to see if the names are registered on a site such as twitter. How easy would this be to make, what things would I need to know?

View 4 Replies View Related

C++ :: Palindrome - String Subscript Out Of Range

Jun 13, 2014

I am trying to create a simple palindrome program. I get the error string subscript out of range. I believe the error is either in the while or for loops.

#include <cctype>
#include <string>
#include <iostream>
using namespace std;
//cleans string, converts to lower
bool cleanTolower(const string& s);

[Code] ....

View 2 Replies View Related

C/C++ :: Reverse A String And State If It Is A Palindrome

Mar 28, 2015

I am supposed to take the three string lines from a text file and then individually reverse them and state whether or not they are a palindrome. I have the three lines from the text file into string variables already but I am not sure on how to reverse them and then see if they are the same reversed(palindrome)

Here is my code so far -->

#include <iostream>
#include <string>
#include <cctype>

[Code].....

EDIT: Ignore line 123 and down in the code. That was merely test code and will not be used.

View 7 Replies View Related

C/C++ :: Find Out Whether A String Can Form A Palindrome Or Not

Sep 25, 2014

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
void findPalind(char *arr) {
int i,j,n,odd,flag=0,count[26]={0};

[Code] ....

This question was asked in Hackerrank. [URL] ....

I am able to get correct output upto a input of 50000 character string, but not for 100000 character string.

View 12 Replies View Related

C++ :: CPP Program To Check Whether A Number Is Palindrome Or Not?

Feb 12, 2014

I could not find the mistake in this program....

Code:
//cpp program to check whether a number is palindrome or not
#include<iostream.h>
#include<conio.h>
//the class
class palindrome

[Code] ....

View 4 Replies View Related

C :: Program To Check If Phrase Is Palindrome Or Not

Nov 8, 2013

I get this error..In function 'main':

p6.c.text+0x6a): undefined reference to 'palindromeness'
collect2: 1d returned 1 exit status

This is program is suppose to check if a phrase is a palindrome or not.I need to write a function definition for _Bool palindromeness(char str[])but I am having a tough time figuring that part out. I am brand new to programming..this is my first class and I am just learning arrays and pointers.

View 4 Replies View Related

C++ ::  Palindrome Program Compile Error

Jan 16, 2014

Here is the code which I wrote in Turbo C++...its giving errors..

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
voidmain() {
clrscr();

[code]....

View 8 Replies View Related

C++ :: Determine Number Of Times Change Each Specific Character In String To Make It Palindrome

Feb 19, 2015

I'm trying to determine the number of times I have to change each specific character in a string to make it a palindrome. You can only change a character one at a time from the end.

Example: "abc" -> "abb" -> "aba" should print 2. "aba" will print 0 because it's already a palindrome. "abcd" -> "abcc" -> "abcb" -> "abca" -> "abba" will print 4 because it took 4 changes to make a palindrome.

I'm not too sure how to approach this - I figured out the case where if it's a palindrome (if reversed string is the same) then it'll print out a 0.

int main() {
int number;
cin >> number; //expecting a number for first line user input
for (int i = 0; i < number; i++) {
string str;

[Code] ....

View 1 Replies View Related

C/C++ :: Palindrome Program - Cstrings Using Strtok Function

Feb 28, 2014

I had an assignment to do a palindrome program but im stuck in this part.

"This c-string will be sent to a function that will remove all spaces and punctuation marks from its c-string as well as change any uppercase letters to lowercase. Use string tokens to eliminate the spaces & punctuation marks. Make sure you include the NULL as you concatenate the tokens into a c-string. Then copy back into the original c-string for the pass by reference."

void tokenptr(char drome[]) {
char *token;
size_t i;
token = strtok(drome, " ,.!:;?");
while (token != '') {

[Code] .....

I'm pretty sure I did that part except how can i pass this cstring back to main? We really haven't even touched much of pointers except to use strtok().

View 2 Replies View Related

C++ :: Palindrome - Program Goes Into Infinite Loop Whenever Word With White Spaces Added

Feb 9, 2013

I have an assignment where i have to make a palindrome program. As you can see i have already done the basic palindrome prog, however i am now stuck since the program goes into a infinite loop whenever a word with whitespaces is added.

I have also tried searching for methods online however they do not seem to work for me...

void CPali::check() {
length = strlen(palin);
for (int i = 0, p = length-1; p>i; i++, p--) {
if (palin[i] == ' ')

[Code] ....

View 6 Replies View Related

C :: How To Handle Enum Checks In Function Arguments

Aug 31, 2013

As we know in C there is no checking if values passed to a function that takes enum are correct, that is if they have been defined in this enum. Example from Enums in C | Occasionally sane ([code] tags don't work on my fx 18.0.1 this is why I put in on pb): [URL] ......

Here c - How to check if an enum variable is valid? - Stack Overflow they say that common convention is add check whether value passed as the parameter is not bigger than the maximum value in enum. But how about situations when enum is composed of numbers from 1-20 and then from 500-510?

View 4 Replies View Related

C++ :: Make A Function That Checks If Array Is A Permutation

Feb 16, 2014

I need to create a function with the following prototype:

bool isPermutation( const unsigned a[], unsigned elements );

unsigned a[] = {3, 0, 2, 1};
bool P1 = isPermutation( a, 4 );
would set P1 to true because the set of subscripts is {0, 1, 2, 3}, and the values are just a reordering of those values. On the other hand,

unsigned a[] = {3, 0, 2, 3};
bool P2 = isPermutation( a, 4 );
would set P2 to false because the set of subscripts is {0, 1, 2, 3}, but there’s no value that’s equal to 1.

I'm not exactly sure how to do this. I thought about it a couple different ways. I first thought about taking the range (max/min) and then checking to see if the numbers in between are equal from each other, distance-wise.

I then thought that I should just make this basically a sort function (I used bubble-sort), and then to just check if the numbers are equi-distant from each other.

This is my basic bubble-sort. Perhaps it is wrong, but I'm not certain...Perhaps I am making this function harder than it has to be.

unsigned temp = 0;
for (unsigned i = 0; i < elements; i++){
for (unsigned k = 0; k < elements-1; k++){
if (a[k] > a[k+1]){
temp = a[k+1];
a[k+1] = a[k];
a[k] = temp;
}}}

Should I do a sort like this, and then do something where I subtract a[i+1] - a[i], and see if that equals '1'?. I would think that would mean they would have to be equidistant. Even if this is correct, I feel like it could be more efficient.

View 4 Replies View Related

C++ :: How To Find Palindrome

Dec 2, 2013

how to get this program to find the palindrome? Here is my program:

#include <iostream>
#include <string>
using namespace std;
using std::string;

[code].....

View 2 Replies View Related

C++ :: Palindrome Loop Error

Oct 5, 2013

My loop keeps getting an error and I don't know why?

#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main (){
int loop;
string word;

[Code] ....

View 3 Replies View Related

C :: Function Which Can Recognize Whether A Word Is Palindrome

Jun 24, 2013

I'm trying to write a function which can recognize whether a word is a palindrome. if it's the case , it must return 1 on screen, otherwise 0. This is the code which return 0 even in case of a palindrome...

Code:
int IsPalindrom(char String[]){
int i,l;
int counter=0;
for(i=0;;i++){ //counts the number of array elements

[Code] ....

View 9 Replies View Related

C/C++ :: Palindrome Function Only Return False?

Apr 29, 2015

I have a text file that consists of:

1457887541
Madam
Able was I ere I saw Elba
Straw? No, too stupid a fad. I put soot on warts.
Class is cancelled today

And all of them are returning false as a palindrome and am not sure why that is so.

bool isPalindrome(const char *input){
int first = 0;
int last = strlen(input) - 1;

//begin loop to compare first position with last
while(last > first){

[Code] .....

View 3 Replies View Related

C++ ::  Recursive Palindrome Test With Merge Sorting

May 28, 2013

My assignment is to make a program that tests whether something is a Palindrome or not using a recursive function. Also, in order to test what type the Palindrome is (if it is indeed a palindrome) I'll need to merge sort it. Now alphabet characters, spaces, and numbers are all allowed, as long as the spaces line up with the spaces in the original input. And yes this is user inputted. I can show you what I've got so far and then I'll tell you what my problem is.

#include <iostream>
#include <istream>
#include <string>
#include <string.h>
#include <conio.h>
using namespace std;
/************To Test if Palindrome*******************/
bool IsPalindrome(char *str, int size) {
if( str[0] == str[size-1]);

[Code] .....

Now my problem is that I can't seem to get the test to work correctly. Since the word is user inputted I don't have any way of knowing the size so that kind of complicates it a little bit. The other thing is I was told by my professor that I need a boolean flag to make it work, and I need to set the value to the return of the IsPalindrome function. I'm not sure how to do that. I also don't haven't been able to add in the MergeSort yet, so the Order and Type don't really work correctly because I'm not sure how to get int len for it. (len is length)

View 3 Replies View Related

C++ :: Identifying Palindrome Words - Running Into Segmentation Fault

Jul 16, 2013

I have written this program with the intention of identifiying palindrome words. Why I am running into a segmentation fault ?

Code:
#include <vector>
#include <iostream>
#include <string>
bool is_palindrome ( const std::string & s )

[Code] .....

View 6 Replies View Related

C :: How To Count And Display Palindrome Words In A Randomized Letters

Oct 11, 2013

how to count and display the palindromes in this randomized letters:

this is my program but it only prints randomized letters and can't count the palindromes words and display it:

Code:
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

[Code].....

View 2 Replies View Related

C :: Program Where User Inputs A String And Prints Out Length Of String

Jan 29, 2014

I would like to understand a function on strings. Below is a code that I took from my teacher where the user inputs a string and prints out the length of the string.

Code:
#include <stdio.h>
#include <string.h>
int main() {
char str[100];
int i = 0;

[Code] ....

Now I understand that it returns the count in "int" so my question is:

Let's say i declared

Code: int count = 0;
at the beginning of the code and then made
Code: count = strlen(str);
why wouldn't i have the same result? Is there a way to do it also?

View 7 Replies View Related

C++ :: Palindrome That Takes A Vector Parameter And Returns True Or False

Apr 26, 2014

Write a function palindrome that takes a vector parameter and returns true or false according to whether the vector does or does not read the same forward as backward (e.g., a vector containing 1, 2, 3, 2, 1 is a palindrome, but a vector containing 1, 2, 3, 4 is not).

Code :
#include <vector>
#include <iostream>
using namespace std;
void palindrome(vector<int>);

[Code] .....

View 4 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved