date issue

hi all:

I want to create a new file dynamically for each day.how can i do this.

 eg..
      struct tm tm;
      while\(1\)
      \{
          if\(tm.tm_hr==0 && tm.tm_min=0 && tm.tm_sec==0\)
              \{
                  //create a new file..
                  printf\("%d%d%d",tm.tm_hr,....\);
               \}
           else
              \{
                  //continue writing to the old file.
              \}
     \}

but when i try to print the time inside the while(),the min,sec does not change accordingly..why?(i mean it should print the system time dynamically).

Can you show where you are calling the localtime() function to populate the tm struct? I think that your code should also be having:

tm=localtime(time());

somewhere, before you check that if condition.

yes, i have used localtime function in my code. this function is used right above the if condition inside the while loop. Even then time is not changing dynamically.

try this,

# include <time.h>
# include <stdio.h>

int main()
{

time_t  logtime;
 struct tm *now = NULL;

while (1)
{
time(&logtime);
 now=localtime(&logtime);
 fprintf(stderr, "HR: %d MIN: %d SEC: %d\n", now->tm_hour, now->tm_min, now->tm_sec);
 sleep(5);
 }
 return 0;
 }