C++ :: Check A String To Be Palindrome
Apr 23, 2014I 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 RepliesI 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 RepliesSo 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] .....
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] ....
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.
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] .....
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] .....
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] .....
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] ....
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.
#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.
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] ....
I want to check whether a certain character is in a string or not but my code is not working
Code:
#include<stdio.h>
#include<string.h>
int main()
{
[Code].....
my program only checks the first character of the string.. D:
View 8 Replies View RelatedIf there is a simple way to check if a file contain a string?
View 1 Replies View RelatedI made this function to check in string is alpha only or alphanumeric but always give me alfa way ?
Code:
int checkIfStringisAlfa(const char str[]){
int lenStr = getStringLength(str);
int i = 0;
int ret;
for(i = 0; i < lenStr; i++){
if(str[i] >= 'a' && str[i] <= 'z' || str[i] >= 'A' && str[i] <= 'Z'){
//printf(" alfa
[Code] .....
I'm trying to check to see if a string from standard input is alphanumeric or not. I feel as though there may be a function for this but...
Code:
for(test_pass = i; test_pass < i; i++){
if(test_pass[i] == ('1', '2', '3', '4', '5', '6', '7', '8', '9', '0'))
printf("Your password is alphanumeric!
");
}
The compiler wasn't too happy with this.
Ii made one string variable and called it email_confirm. I used cin to get the users email but i don't know to check if the email is real.(without being connected to the internet).
For example,in PHP you can use ereg() or eregi() to see if the email is real, I mean you can see how many characters the email_confirm is made off or how many characters is used after the @ or . is used. is there any functions for this?
I'm fairly new to C++ and programming in general and I'm trying to get a program to check the parameters of a binary string before converting that string to dec values. I have the user input 'num' line 39 - 42, but I want to reuse that same value in the 'void bin_to_dec()' function. Is there anyway I can use the same variable between void functions?
13 #include <bitset>
14 #include <sstream>
15 using namespace std;
16
17 void dec_to_bin(){
18 string mess;
[Code] ....
How i could go about extracting and checking if the very first character in my string array is an alphabet
View 2 Replies View RelatedI'm trying to write a short program that takes the input from a user and trims any leading/trailing white space, and then checks how many words are in the string. Problem is, I'm only allowed to use stdio.h and stdlib.h. How can I accomplish this? Also, how would I check if any of the characters which were entered aren't either a number, letter, or '-'?
View 3 Replies View Relatedhow to get this program to find the palindrome? Here is my program:
#include <iostream>
#include <string>
using namespace std;
using std::string;
[code].....
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] ....
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] ....
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]....
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] .....
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 != '