Early on I am able to use cin.getline(input2, 40) to assign a line to input2. I do it as well so that I have two c strings with information in them.
Later I enter a switch where people can over write one of the c string lines. When it executes cin.getline(input2, 40); as the option, all it does is delete the information at that string.
I've tried removing assigning the cstring at the beginning, allowing it to be changed in the switch, but it isn't assigned, rather just goes back to the switch statement.
I've tried using cin.getline(input2, 40, '\n') so that cin waits for a new line before continuing, but it seems it is automatically getting one.
The switch option for input is 'i'.
I've struggled with it for the last hour or so, so now I humbly ask for your assistance.
Bonus points to someone that finds out why when I put in x, the switch statement doesn't end.
#include<iostream>
#include<conio.h>
#include<string>
#include<algorithm>
using namespace std;
char rev (char *);
bool compareChar (char *, char *);
int getLength(char *);
string concat1 (char *, char *);
int main()
{
char input1[80];
char input2[80];
char *input1Ptr = input1;
char *input2Ptr = input2;
int length = 0;
string concat = "None";
cout << "Input a line of text for line 1: ";
cin.getline(input1, 40);
cout << "Input a line of text for line 2: ";
cin.getline(input2, 40);
char in;
while (in != 'x' || in != 'X'){
cout << endl;
cout << endl;
cout << "Enter i for Input" << endl;
cout << "Enter r for Reverse" << endl;
cout << "Enter c for compare" << endl;
cout << "Enter o for concatenate" << endl;
cout << "Current concatenate is " << concat << endl;
cout << "String a" << endl;
cout << "String b" << endl;
cout << "Enter x to exit" << endl;
cin >> in;
switch (in) {
case 'i':
case 'I':
cout << endl;
cout << "Rewrite Line 2: " << endl;
cin.getline(input2, 40, '\n');
cout << input2;
break;
case 'r':
case 'R':
length = getLength(input1);
reverse(input1, input1 + length);
cout << input1;
break;
case 'c':
case 'C':
if (compareChar(input1Ptr, input2Ptr) == 1){
cout << "True" << endl;
}
else {
cout << "False" << endl;
}
break;
case 'o':
case 'O':
concat = concat1(input1, input2);
cout << concat;
break;
case 'a':
case 'A':
cout << input1;
break;
case 'b':
case 'B':
cout << input2;
break;
default:
cout << "Syntax Error";
in = 'x';
break;
}
}
}
string concat1 (char *a, char *b){
string con;
con += a;
con += b;
return con;
}
char rev (char *a){
int length1 = 0;
int counter = 0;
int incr = 0;
char backward[40];
while (*a) {
cout << *a << " " ;
length1++;
a++;
}
counter = length1;
while (counter > 0){
backward[incr] = a[counter];
counter--;
incr++;
}
return backward[40];
}
bool compareChar (char *a, char *b){
int counter = 0;
bool comparing = false;
while (counter < 40){
if (a[counter] == b[counter]){
counter++;
comparing = true;
}
else {
counter = 40;
}
}
return comparing;
}
int getLength(char *input1)
{
int length = 0;
while (*input1){
input1++;
length++;
}
return length;
}