Problem in struct
-
Hi All I got example of get file size from MSDN.But i have a problem to write out put in file.How to convert struct values to CString or any other solution. Example code is here
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <errno.h>int main( void )
{
struct _stat buf;
int result;
char timebuf[26];
char* filename = "crt_stat.c";
errno_t err;// Get data associated with "crt_stat.c":
result = _stat( filename, &buf );// Check if statistics are valid:
if( result != 0 )
{
perror( "Problem getting information" );
switch (errno)
{
case ENOENT:
printf("File %s not found.\n", filename);
break;
case EINVAL:
printf("Invalid parameter to _stat.\n");
break;
default:
/* Should never be reached. */
printf("Unexpected error in _stat.\n");
}
}
else
{
// Output some of the statistics:
printf( "File size : %ld\n", buf.st_size );
printf( "Drive : %c:\n", buf.st_dev + 'A' );
err = ctime_s(timebuf, 26, &buf.st_mtime);
if (err)
{
printf("Invalid arguments to ctime_s.");
exit(1);
}
printf( "Time modified : %s", timebuf );
}
}How can i write it's values
buf.st_size
in file. Plz help me -
Hi All I got example of get file size from MSDN.But i have a problem to write out put in file.How to convert struct values to CString or any other solution. Example code is here
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <errno.h>int main( void )
{
struct _stat buf;
int result;
char timebuf[26];
char* filename = "crt_stat.c";
errno_t err;// Get data associated with "crt_stat.c":
result = _stat( filename, &buf );// Check if statistics are valid:
if( result != 0 )
{
perror( "Problem getting information" );
switch (errno)
{
case ENOENT:
printf("File %s not found.\n", filename);
break;
case EINVAL:
printf("Invalid parameter to _stat.\n");
break;
default:
/* Should never be reached. */
printf("Unexpected error in _stat.\n");
}
}
else
{
// Output some of the statistics:
printf( "File size : %ld\n", buf.st_size );
printf( "Drive : %c:\n", buf.st_dev + 'A' );
err = ctime_s(timebuf, 26, &buf.st_mtime);
if (err)
{
printf("Invalid arguments to ctime_s.");
exit(1);
}
printf( "Time modified : %s", timebuf );
}
}How can i write it's values
buf.st_size
in file. Plz help meI'm not quite sure what you're after, but in pure C stuff, you can write values to a file like so:
FILE *f;
...
f = fopen ("c:\\myfile.abc", "w"); // makes a new empty file.
...
fprintf (f, "Some Integer: %i\n", nMyInt); // could be buf.st_size if you like
...
fclose (f);I hope that puts you on the right path, Iain.
In the process of moving to Sweden for love (awwww). If you're in Scandinavia and want an MVP on the payroll (or happy with a remote worker), give me a job!
-
Hi All I got example of get file size from MSDN.But i have a problem to write out put in file.How to convert struct values to CString or any other solution. Example code is here
#include <time.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>
#include <errno.h>int main( void )
{
struct _stat buf;
int result;
char timebuf[26];
char* filename = "crt_stat.c";
errno_t err;// Get data associated with "crt_stat.c":
result = _stat( filename, &buf );// Check if statistics are valid:
if( result != 0 )
{
perror( "Problem getting information" );
switch (errno)
{
case ENOENT:
printf("File %s not found.\n", filename);
break;
case EINVAL:
printf("Invalid parameter to _stat.\n");
break;
default:
/* Should never be reached. */
printf("Unexpected error in _stat.\n");
}
}
else
{
// Output some of the statistics:
printf( "File size : %ld\n", buf.st_size );
printf( "Drive : %c:\n", buf.st_dev + 'A' );
err = ctime_s(timebuf, 26, &buf.st_mtime);
if (err)
{
printf("Invalid arguments to ctime_s.");
exit(1);
}
printf( "Time modified : %s", timebuf );
}
}How can i write it's values
buf.st_size
in file. Plz help meSomething like this:
CString csOut;
csOut.Format("File size : %ld\n", buf.st_size);Then use
CStdioFile::WriteString()
to write to a file. -
Something like this:
CString csOut;
csOut.Format("File size : %ld\n", buf.st_size);Then use
CStdioFile::WriteString()
to write to a file.