more date validation

This is a discussion on more date validation within the C Programming forums, part of the General Programming Boards category; Hi coud someone give me an example to validate a date. dd/mm/yyyy and to make sure that if any other ...

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,338
    We just did this already
    DATE <TIME.H> data validation
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,338
    Continue here compile errors with date program
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21