Thread: plz help me geeting the date is correct or not

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    26

    plz help me geeting the date is correct or not

    Code:
    memset(a,'\0',11);
            memset(str_date,'\0',9);
    
            strncpy(a,path_departure_date,4);
    
            result=strtok(a,delims);
    
            while(result!=NULL) {
                    strcat(str_date,result);
                    result=strtok(NULL,delims);
            }
    
            yyyy_path_departure_date=atoi(str_date);
    The requirement i got is path_departure_date is having 2008-06-05 i want yyyy_path_departure_date year filed only 2008 .I want to conform whether the code i written is correct or not

    Thanks & Regards,
    vijay

  2. #2
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    if you know you need 4 bytes - why this long code, playing with strtok?

    if you just want to convert first part of the string to int why not to use strtol directly on the "2008-06-05" string? it should stop as soon as non-digit is encountered... Also giving you pointer where the conversion is stopped, so you can skip '-' and convert the next part...
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Checking array for string
    By Ayreon in forum C Programming
    Replies: 87
    Last Post: 03-09-2009, 03:25 PM
  2. Replies: 6
    Last Post: 08-29-2007, 08:52 PM
  3. How can I verify if a date is correct?
    By ^DJ_Link^ in forum C Programming
    Replies: 11
    Last Post: 01-13-2004, 12:47 PM
  4. date calculation
    By tuti in forum C Programming
    Replies: 0
    Last Post: 09-02-2002, 04:50 AM