I am new to C++ and the boards so just wanted to drop in and say hi before I start assaulting you with stupid questions. ;)
Actually I just started my first real project ( parsing a firewall log ) and everything was going spectacularly until I threw some bad strings at it.... crash n burn.
Was using the string.find() and string.assign() to do the majority of my parsing, but I think what crashed was the atoi() conversions to test IP addys and dates. Anyway it was pretty awesome cause even though I failed it was a great learning experience.
Sure I will be back with questions soon enough. :D
EDIT: Here's the code that is failing I think... pretty sure gonna rewrite whole program though.
EDIT EDIT: Should mention if the string is constructed properly this works great, but throw some bad data and it goes poof and crashes.
Code:int parseTXT::checkDate(string checkD) {
int chkYear, chkMonth, firstD, secondD, chkDay;
firstD = checkD.find("-",0);
secondD = checkD.find("-", (firstD + 1));
chkYear = atoi((checkD.assign(checkD.begin()+0, checkD.begin()+firstD)).c_str());
chkMonth = atoi((checkD.assign(checkD.begin()+(secondD - 2), checkD.begin()+secondD)).c_str());
chkDay = atoi((checkD.assign(checkD.begin()+(secondD + 1), checkD.begin()+(secondD + 3))).c_str());
if ((chkYear < 1990) || (chkYear > 2100)) {
return 0;
}
if ((chkDay <= 0) || (chkDay > 31)) {
return 0;
}
if ((chkMonth <= 0) || (chkMonth > 12)) {
return 0;
}
return 1;
}