O
one2001boy
Hello,
I tried to find the access time of a file using stat() function.
but the following C code in windows vc.net 2003 always give
the same access time. the same code works correctly in linux gcc.
do I miss something?
#include <stdio.h>
#include <sys/stat.h>
int main() {
struct stat sbuf;
char *name="testfile";
FILE *fd;
char result[100];
if(!stat(name, &sbuf) )
{
printf("atime = %d\n", sbuf.st_atime);
}
fd = fopen(name, "r");
if(!stat(name, &sbuf) )
{
printf("atime = %d\n", sbuf.st_atime);
}
fread(result, 3,1, fd);
if(!stat(name, &sbuf) )
{
printf("atime = %d\n", sbuf.st_atime);
}
fclose(fd);
if(!stat(name, &sbuf) )
{
printf("atime = %d\n", sbuf.st_atime);
}
return 0;
}
thanks.
I tried to find the access time of a file using stat() function.
but the following C code in windows vc.net 2003 always give
the same access time. the same code works correctly in linux gcc.
do I miss something?
#include <stdio.h>
#include <sys/stat.h>
int main() {
struct stat sbuf;
char *name="testfile";
FILE *fd;
char result[100];
if(!stat(name, &sbuf) )
{
printf("atime = %d\n", sbuf.st_atime);
}
fd = fopen(name, "r");
if(!stat(name, &sbuf) )
{
printf("atime = %d\n", sbuf.st_atime);
}
fread(result, 3,1, fd);
if(!stat(name, &sbuf) )
{
printf("atime = %d\n", sbuf.st_atime);
}
fclose(fd);
if(!stat(name, &sbuf) )
{
printf("atime = %d\n", sbuf.st_atime);
}
return 0;
}
thanks.