Thanks to what you guys said, i came up with this idea:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
#include<iostream>
#include<string>
#include<ctime>
using namespace std;
const int CAPACITY=50;
int main()
{
string input="";
char sentence[CAPACITY]={};
char sentenceReversed[CAPACITY]={};
cout<<"Enter a sentance or a word: ";
getline(cin, input);
for(int i=0;i<input.size();i++)
{
if(input.at(i)!=' ')
{
sentence[i]=input.at(i);
cout<<sentence[i];
}
}
cout<<endl;
return 0;
}
|
This code puts the input: "Hello there" into the array "sentence" like this: "Hellothere". And that is what i wanted.
Now i came up with a new problem *sigh*
I want the array "sentenceReversed" to store the values from "sentence" but from last to first.
Visual:
|H| |E| |L| |L| |O| <-- sentence[CAPACITY]
|O| |L| |L| |E| |H| <-- sentenceReversed[CAPACITY]
Cause then i can check if a word or senctence is equal with its reversed array and in that case it's a palindrome. First i tried to create an
int counter= 0
This counter were supposed to increase everytime a word was copied from the input to the sentence array. Then i could use the counter like this:
1 2 3 4 5 6
|
for(...)
{
sentenceReversed[counter-1]=sentence[i];
counter--;
}
|
But this did not work.
If you have an idea to solve this, I would be glad if i could get som hints or ideas :)