ref: seperated strings into pair
The problem is enter a string and seperate into space.
1) if char1==char2 replace char2 with 'x' LL ->Lx
2) if one of char not in pair add 'x' to single char eg he ll o-> ox
Here is my code for it can anyone please show me how to improve the code, thank you?
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cctype>
using namespace std;
int main()
{
string input;//input string
char ch1, ch2;//ch1 and ch2 (ch1 is the first letter of pair)
int length;//length of input string
int count=0;
char pairList[count][2];//combine pairs
char encrypt[2];//store the encrypted pairs
int pairCount=0;//count number of pairs
int pairIndex=0;
cout<<"Please enter string: ";
getline(cin,input);//get lines of string
length = input.length();
//sepearte input string into non encrypted pairs
for (int i=0; i<=length; i=i+2)
{
ch1 = input[i];
ch2 = input[i+1];
pairCount++;
//put 'x' into pair depends on one of the condition
if (ch1==ch2)
ch2='x';
if (isspace(ch2))//if ch2 is space
ch2='x';
if (isspace(ch1))
ch1=='x';
cout<<ch1<<ch2<<endl;
}//end loop
system("pause");
return 0;
}//end main