EmilKh
February 15th, 2008, 07:59 PM
User has to input date in mm/dd format, anything else creates error:
cout << "Please enter the month and day (mm/dd) >> ";
cin.getline(buffer, 80);
if (strpbrk("/", buffer))
{
month = atoi ( strtok(buffer, "/") );
if (NULL)
day = atoi (strtok(NULL, "\n") );
}
if (month < 1 || month > 12 || day < 1 || day > 31)
cout << buffer << " is not a valid date.";
It's working in 99.99% cases. 0.01% is input like "/", which screws me up and "Bus error" appears. Any ideas?
cout << "Please enter the month and day (mm/dd) >> ";
cin.getline(buffer, 80);
if (strpbrk("/", buffer))
{
month = atoi ( strtok(buffer, "/") );
if (NULL)
day = atoi (strtok(NULL, "\n") );
}
if (month < 1 || month > 12 || day < 1 || day > 31)
cout << buffer << " is not a valid date.";
It's working in 99.99% cases. 0.01% is input like "/", which screws me up and "Bus error" appears. Any ideas?