If you really want to use fopen() to create a log file (which I'm sure you don't - whatever you're writing it's not C) then rather than mess about with renaming files just append the time the file was created to a base name. Then they sort nicely in a directory.
[Warning, this is going to get ugly... I'm not the best C programmer anymore, if I ever was any good]
#include <time.h>
#include <stdio.h>
#include <time.h>
#include <stdio.h>
int main()
{
char file_name[ 128 ] = { 0, };
int file_name_size = sprintf( file_name, "log_file_%u.txt", time( 0 ) );
if( file_name_size < 128 && file_name_size > -1 )
{
FILE *fp = fopen( file_name, "w" );
if( fp )
{
fputs( "Are we open?", fp );
fclose( fp );
fp = NULL;
}
}
return 0;
}
Anyway, the point of this example is to show you that sticking with whatever your current runtime is far more productive than hacking at a lump of code to do the same thing.
Cheers,
Ash