Hi! I'm trying to write a specific program that compares the character values of two different user inputs of different lengths. Because these inputs can be of any length, I need to accept user input to each index of the vector. This however, is not working, and I'm not sure how implement this? Any help is appreciated!
EDIT:
This is the main part of the code in which I am trying to do this:
//Preprocessor Directives
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <vector>
usingnamespace std;
//Vectors
vector<char> Database;
vector<char> Search_Term;
//Main Function Heading
int main (int argc, char * const argv[]) {
//This 'for' loop places user input into the 'Database' vector, ending, when the user inputs a specific key.
for (p = 0; end_input == true; p++) {
cin >> Database[p];
switch (Database[p]) {
case'|':
Database.pop_back();
end_input = false;
break;
default:
cout << Database[p] << endl;
break;
}
}
cout << endl << endl << "Next, please enter each character of the term you would like to search for throughout the 'Database Terms.' /n It may be part of a name." << endl;
cout << "Also, the same rules apply. When you enter the '|' character, input will end.";
//This 'for' loop places user input into the 'Search_Term' vector, ending, when the user inputs a specific key.
for (p = 0; end_input == true; p++) {
cin >> Search_Term[p];
switch (Search_Term[p]) {
case'|':
Search_Term.pop_back();
end_input = false;
break;
default:
cout << Search_Term[p] << endl;
break;
}
}
cout << endl << endl << "Database Size: " << (char) Database.size() << endl << endl << "Search Term Size: " << (char) Search_Term.size();
i = -1;
index_counter = 0;
return 0;
}
P.S.
Certain variables mentioned are declared in the actual code. This is just a portion that is not working properly. When I compile and run it, it does not allow the user input, but merely runs and ends. It appears to be working though, just not actually taking the input.
the reason is: at end_input == true in the second iteration block, end_input has actually been set to false by the previous for-loop block. So the comparison fails and thus runs to the end (Assuming you entered '|' to end the for-loop database input).