Thread: what happened to the function today

  1. #1
    Registered User
    Join Date
    Jan 2006
    Posts
    32

    what happened to the function today

    Hi
    I have this function, I built 2 days ago, yesrterday it was working perfectly, today not.

    Code:
    char *month(int months, const char *format, char *text, size_t size)
    {
       time_t t;
       if ( time ( &t ) != (time_t)(-1) )
       {
          struct tm *local = localtime ( &t );
          if ( local )
          {
             local->tm_mon += months;
             t = mktime ( local );
             if ( t != (time_t)(-1) )
             {
                local = localtime ( &t );
                if ( local )
                {
                   if ( strftime ( text, size, format, local ) )
                   {
                      return text;
                   }
                }
             }
          }
       }
       return 0;
    }
    I use this function to bring the file of this month, like where are in month 2, so it suppose to bring me the file of month2 daily_report_02.txt , yesterday it brought it to me but today it suppose to bring the same file as we are still in month 2, but it brought me daily_report_03.txt, WWWWWWWWWHyyyyy


    notice please
    one final this because I read a input file of the previous day, so the out put should be put in the same month, what I mean is if today is 1 feb so my code will read the input file of the 31/1/2006 and will put its out put in Jan (Summary_Report_01.txt).
    I use this function and call it in main
    Code:
    ( notes field contain the path)
        string outpath= field + month(-1, "Daily_Report_%d.txt", outfile, sizeof outfile) ;
    ofstream outfile(outpath.c_str(), ios::out | ios::app);
    please fix my error
    Last edited by yes; 02-03-2006 at 05:02 AM.

  2. #2
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    That looks more like a C program to me...
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  3. #3
    Registered User
    Join Date
    Jan 2006
    Posts
    32
    I do not have a complier error in it,

    The Function did not bring this month.
    I use this function to bring the file of this month, like where are in month 2, so it suppose to bring me the file of month2 daily_report_02.txt , yesterday it brought it to me but today it suppose to bring the same file as we are still in month 2, but it brought me daily_report_03.txt,
    one final this because I read a input file of the previous day, so the out put should be put in the same month, what I mean is if today is 1 feb so my code will read the input file of the 31/1/2006 and will put its out put in Jan (Summary_Report_01.txt).

    can you help in fix that error, even if you suggest either to modify the function or build new one.

    help it is really ergent, I do know how to fix it.
    Last edited by yes; 02-03-2006 at 05:03 AM.

  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
    How about using the right percent character for month, rather than day then in your format string.

  5. #5
    Registered User
    Join Date
    Jan 2006
    Posts
    32
    Hi Salem

    If i got you idea right, this will be affected, by the end of the month and the begining
    because I read a input file of the previous day, so the out put should be put in the same month, what I mean is if today is 1/2/2006 so my code will read the input file of the 31/1/2006 and it suppose to put its out put in Jan (Summary_Report_01.txt). even we start Feb., beacuse the file the code read is 31/01/206 so the result should be put in Summary_report_01.txt

  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
    > local->tm_mon += months;
    If you want the previous day, then subtract 1 day, not one month.

  7. #7
    Registered User
    Join Date
    Jan 2006
    Posts
    32
    thak you all I did it
    Last edited by yes; 02-03-2006 at 08:20 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Seg Fault in Compare Function
    By tytelizgal in forum C Programming
    Replies: 1
    Last Post: 10-25-2008, 03:06 PM
  2. Another syntax error
    By caldeira in forum C Programming
    Replies: 31
    Last Post: 09-05-2008, 01:01 AM
  3. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  4. Including lib in a lib
    By bibiteinfo in forum C++ Programming
    Replies: 0
    Last Post: 02-07-2006, 02:28 PM
  5. const at the end of a sub routine?
    By Kleid-0 in forum C++ Programming
    Replies: 14
    Last Post: 10-23-2005, 06:44 PM