comfort_17
03-15-2002, 04:30 AM
I am a very bad c programmer and can not get the following code to work. Please could someone either assist me on how to make the code work or just do the code an email me at comfort_17@yahoo.com. THe code should check the date of a file and output it.
the structure returned include:
st_atime
Time of last file access.
st_ctime
Time of creation of file.
st_dev
If a device, handle; otherwise 0.
st_mode
Bit mask for file-mode information. The _S_IFCHR bit is set if handle refers to a device. The _S_IFREG bit is set if handle refers to an ordinary file. The read/write bits are set according to the file’s permission mode. _S_IFCHR and other constants are defined in SYS\STAT.H.
st_mtime
Time of last modification of file.
st_nlink
Always 1 on non-NTFS file systems.
st_rdev
If a device, handle; otherwise 0.
st_size
Size of the file in bytes.
/* FSTAT.C: This program uses _fstat to report
* the size of a file named F_STAT.OUT.
*/
#include "io.h"
#include "fcntl.h "
#include "time.h "
#include "sys/types.h "
#include "sys/stat.h "
#include "stdio.h "
#include "stdlib.h "
#include "string.h"
void main( void )
{
struct _stat buf;
int fh, result;
char buffer[] = "A line to output";
if( (fh = _open( "f_stat.out", _O_CREAT | _O_WRONLY |
_O_TRUNC )) == -1 )
_write( fh, buffer, strlen( buffer ) );
/* Get data associated with "fh": */
result = _fstat( fh, &buf );
/* Check if statistics are valid: */
if( result != 0 )
printf( "Bad file handle\n" );
else
{
printf( "File size : %ld\n", buf.st_size );
printf( "Time modified : %s", ctime( &buf.st_ctime ) );
}
_close( fh );
}
Output
File size : 0
Time modified : Tue Mar 21 15:23:08 1995
the structure returned include:
st_atime
Time of last file access.
st_ctime
Time of creation of file.
st_dev
If a device, handle; otherwise 0.
st_mode
Bit mask for file-mode information. The _S_IFCHR bit is set if handle refers to a device. The _S_IFREG bit is set if handle refers to an ordinary file. The read/write bits are set according to the file’s permission mode. _S_IFCHR and other constants are defined in SYS\STAT.H.
st_mtime
Time of last modification of file.
st_nlink
Always 1 on non-NTFS file systems.
st_rdev
If a device, handle; otherwise 0.
st_size
Size of the file in bytes.
/* FSTAT.C: This program uses _fstat to report
* the size of a file named F_STAT.OUT.
*/
#include "io.h"
#include "fcntl.h "
#include "time.h "
#include "sys/types.h "
#include "sys/stat.h "
#include "stdio.h "
#include "stdlib.h "
#include "string.h"
void main( void )
{
struct _stat buf;
int fh, result;
char buffer[] = "A line to output";
if( (fh = _open( "f_stat.out", _O_CREAT | _O_WRONLY |
_O_TRUNC )) == -1 )
_write( fh, buffer, strlen( buffer ) );
/* Get data associated with "fh": */
result = _fstat( fh, &buf );
/* Check if statistics are valid: */
if( result != 0 )
printf( "Bad file handle\n" );
else
{
printf( "File size : %ld\n", buf.st_size );
printf( "Time modified : %s", ctime( &buf.st_ctime ) );
}
_close( fh );
}
Output
File size : 0
Time modified : Tue Mar 21 15:23:08 1995