Please change my code to see if name 1 is = to name2 listed in an array of strings- should i make the following code a function. I am thinking of making the following code a function(get token) and then use if for each name. Then I would use a compare function to compare each name. How am i passing the array through the parameters and how would the compare function go...
here is my code so far...
#include < iostream >
#include < string >
using namespace std;
int main()
{
int len1; int pos_sp, pos_comma, pos_period;
// position of space, etc
string name1, partial_name; string token1, token2, token3 = " ";
name1 = "trixie, cee c."; // string w/4 tokens
len1 = name1.length(); // get length of string
pos_sp = name1.find(' '); // get location of 1st space
token1 = name1.substr(0,pos_sp); // get 1st token
partial_name = name1.substr(pos_sp + 1, len1 - 1); // create new string
//print 1st token and remainder of string
cout << endl << token1 << endl << partial_name << endl;
//now scan for a period pos_period = token1.find('.'); if (pos_period < 0)
cout << "No period found" << endl;
else
{
token1 = token1.substr(0, pos_period); // remove the period
cout << "I have removed the period" << endl;
cout << token1 << " this token was an initial" << endl;
}
//now scan for a comma pos_comma = token1.find(','); if (pos_comma < 0)
cout << "No period found" << endl;
else
{
token1 = token1.substr(0, pos_comma); // remove the comma
cout << "I have removed the comma " << endl;
cout << token1 << " this token was a LAST name" << endl;
}
return 0;
}