I'm trying to create a code that will parse through a csv database with stock information. Currently, I have the code generated so that it will search with a keyword and print the whole row, but I'm trying to get it so that it will print the whole row with the header row in a neatly formatted way.
I'm trying to get it so that if I searched Google, it'd return
Symbol GOOG
NAME Google Inc
High Today $568.77
How the csv looks like:
Symbol,Name,Price,High Today,Low Today,52 Week Low
GOOG,Google Inc.,$568.77 ,$570.25 ,$560.35
AAPL,Apple Inc.,$93.28 ,$63.89 ,$99.44.
Code:
string NameSearch::getInput()
{
cout << "Enter the name of the company you would like to search for: ";
getline(cin, input);
return input;
}
void NameSearch::NameAlgorithm()
{
string line;
ifstream fs("Stock Database.csv");
while (!fs.eof())
{
getline(fs, line);
string companyname = "";
string a;
int column = 1;
int commacount = 0;
int ChrCount = 0;
while (line != "\0")
{
a = line[ChrCount];
ChrCount++;
if (a == ",")
{
commacount++;
}
else if (commacount == column)
{
companyname.append(a);
}
else if (commacount > column)
{
break;
}
if (companyname == input)
{
cout << endl << line;
}
}
}
}