arunplr 0 Newbie Poster

Hai ,
For that last two hours i have been troubling with a problem.
I want to get the modified date of a text file. i wrote a sample program , worked fine. But when i attached this program as a function to my actual application , it shows the modified date of file as
01/01/1970 05:30:00. it cannot show the actual modified date. For any file it is showing the same date. What can be the problem.?
Please help me to solve this problem .
Program given below...

char file[] = "/etc/passwd";
  char t_current[ 100 ] = "";
  char t_previous [100] ="";
  struct stat b;
  if (!stat(file, &b)) {
    strftime(t_current, 100, "%d/%m/%Y %H:%M:%S", localtime( &b.st_mtime));
    strftime(t_previous, 100, "%d/%m/%Y %H:%M:%S", localtime( &b.st_mtime));

  }

  while (1)
  {

  if (!stat(file, &b)) {
      cout<<"TIME :"<<localtime( &b.st_mtime)<<endl;
    strftime(t_current, 100, "%d/%m/%Y %H:%M:%S", localtime( &b.st_mtime));


    if(strcmp (t_current,t_previous))
    {
        cout<<"Yessssssssss File change"<<endl;
        strcpy(t_previous,t_current);
        printf("\nLast modified date and time = %s\n", t_current);
    }
    else
    {
        cout<<"NOOOOOO file change"<<endl;
                printf("\nLast modified date and time = %s\n", t_previous);

    }
  } 
  else {
    printf("Cannot display the time.\n");
  }

  }
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.