Thread: more date validation

  1. #1
    Musicman - Canora
    Join Date
    Aug 2005
    Location
    Melbourne
    Posts
    252

    more date validation

    Hi coud someone give me an example to validate a date.

    dd/mm/yyyy and to make sure that if any other characters are typed in apart from that date format an input validation occurs.

    so it needs to check for the dd then for a / then for the mm then a / then yyyy.

    Could someone please help me thanks

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Read dd. Read /. Read mm. Read /. Read yyyy. If at the point in any of those you don't have what you want, stop checking.


    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    Musicman - Canora
    Join Date
    Aug 2005
    Location
    Melbourne
    Posts
    252

    example of datevalidation

    thanks fo that.. could you please give me an example im hopeless at c. lol id really appreciate it.

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    We just did this already
    http://cboard.cprogramming.com/showthread.php?t=68445
    Try doing a bit of reading around what you've been shown already.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Musicman - Canora
    Join Date
    Aug 2005
    Location
    Melbourne
    Posts
    252

    heres my code in full im getting compile errors with it

    im kind of having problems with it im getting a token error.
    thats my function


    Code:
    void ageCalculator()
    {
     char buff[BUFSIZ];
     
     int m,d,y;
     struct tm t;
     time_t now;
     
     
    
     time(&now);
     t = *localtime(&now);
     strftime(buff, sizeof(buff), "%Y//%m//%y", &t);
    
     
     printf("Please enter your date of birth in (yyyy//mm/dd) format\n");
    
      if ( fgets( buff, BUFSIZ, stdin ) != NULL ) {
        int y,m,d;
        if ( sscanf( buff, "%d/%d/%d", &d, &m, &y ) == 3 ) {
          /* got 3 ints */
          if ( d >= 1 && d <= 31 ) /* etc etc */
        }
      }
      
      
     printf("The current date is %s\n",buff);
     
    
     
    }

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Continue here http://cboard.cprogramming.com/showthread.php?t=68452
    Try and keep the same thread going while you're still on the same basic question.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Advancing day by day until it matches a second date
    By nhubred in forum C++ Programming
    Replies: 1
    Last Post: 05-30-2009, 08:55 AM
  2. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  3. DATE <TIME.H> data validation
    By bazzano in forum C Programming
    Replies: 4
    Last Post: 08-07-2005, 01:10 AM
  4. date validation !!
    By rajesh23 in forum C Programming
    Replies: 2
    Last Post: 09-24-2003, 03:54 AM