CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Threaded View

  1. #1
    Join Date
    Feb 2008
    Posts
    1

    Validation of user input ( month/day)

    User has to input date in mm/dd format, anything else creates error:
    Code:
    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?
    Last edited by EmilKh; February 15th, 2008 at 09:02 PM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured