substring, date

Hi experts,
I have 2 columns: row_elem[1], and row_elem[10]
for example.
row_elem[1] ,                                 row_elem[10]
aaaaa NFLFAN sssss,                          01022004      date format mmddyyyy
aaaaa NFLFAN sssss,                          01152004
...                                                     ...
I check row_elem[1] first, if substring has NFLFAN, and if dd=15, then print 01162004 ( adding 1 to day, that is 16, always 16 )
otherwise print 01022004

My code is like this, but its not working. please help
...
main(int arc, char *arv[])
{
    ifstream fin("test.csv");
    ofstream fout("fout.txt");
    string row_read;
    while( getline(fin, row_read) )
    {

        vector<string> row_elem;
        GetFields(row_read, row_elem, ',');
....
string mm;
string dd;
string yyyy;

mm = row_elem[10].substr(0,2);
dd = row_elem[10].substr(2,2);
yyyy = row_elem[10].substr(4,4);
//cout << mm.c_str() << endl;

char pch[50];
char *ss1;
ss1 = strstr(row_elem[1],"NFLFAN");
if ( ss1 )
{
     cout << mm16yyyy <<endl;
}
else
     cout << mmddyyyy << endl;
}   // end of while
}

justinYAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

IndrawatiCommented:
I don't really understand your question, but I found a mistake in your code:

if ( ss1 )
{
     cout << mm16yyyy <<endl;
}
else
     cout << mmddyyyy << endl;

Should be

if ( ss1 )
{
     cout << mm << 16 << yyyy <<endl;
}
else
     cout << mmddyyyy << endl;
0
HendrikTYRCommented:
Have you tried:

if ( ss1 )
{
     cout << mm << "16" << yyyy << endl;
}
else
     cout << mm << dd << yyyy << endl;
}
0
HendrikTYRCommented:
Sorry, posted same time
0
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

itsmeandnobodyelseCommented:
That is wrong as well:

>>>> ss1 = strstr(row_elem[1],"NFLFAN");

change to

      if ( row_elem[1].find("NFLFAN") != string::npos)
     {
        cout << mm << "16" << yyyy << endl;
     }
     else
         cout << mm << dd << yyyy << endl;
    }

Regards, Alex

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
HendrikTYRCommented:
... or:

char *ss1;
ss1 = strstr(row_elem[1].c_str(), "NFLFAN");
if ( ss1 )
{
     cout << mm << 16 << yyyy <<endl;
}
else
     cout << mm << dd << yyyy << endl;
0
justinYAuthor Commented:
Thanks guys,
I forgot this if dd = 15, then cout <<mm<<16<<yyyy;
so my code is

stringstream oss1;
stringstream oss2;

if ( ( row_elem[1].find("NFLFAN") != string::npos) && (aoti(dd) = 15))
     {
        oss1 << setw(8) << mm << "16" << yyyy;
     }
     else
         oss2 << setw(8) << mm << dd << yyyy;
    }

      fout << setw(8) << oss1.str().c_str() << endl;
but I have compiling error, whats wrong ?
0
itsmeandnobodyelseCommented:
>> && (aoti(dd) = 15)

suppose you want

     && (dd == 15)

instead.

Regards, Alex
0
itsmeandnobodyelseCommented:
Correction: dd is a string, so you need

&& (dd == "15")


Regards, Alex

0
justinYAuthor Commented:
Hi Alex,

I fixed it by doing this
 && (aoti(dd.c_str()) == 15)

Thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C++

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.