here is an example
This is a cut down version. In ours we use vargs and format them before calling log_it.
typedef const char* c_str;
FILE* log_fp = 0;
const int max_log_size = 4 * 1024 * 1024;
const int max_no = 5;
c_str prefix = "logs_";
c_str postfix = ".txt";
void log_it( c_str str )
{
char file1[100], file2[100];
if( ! log_fp )
{
sprintf( file1 "%s%d%s", prefix, 0, postfix );
log_fp = fopen( file1, "a" );
}
if( log_fp )
{
if( ftell( log_fp ) > max_log_size )
{
fclose( log_fp );
log_fp = 0;
for( int i = (max_no - 1); i >= 0; i-- )
{
sprintf( file1 "%s%d%s", prefix, i, postfix );
sprintf( file1 "%s%d%s", prefix, i+1, postfix );
rename( file1, file2 );
}
sprintf( file1 "%s%d%s", prefix, 0, postfix );
log_fp = fopen( file1, "a" );
}
fputs( str, log_fp );
fflush( log_fp );
}
}
I hope that helps.
dave