- 论坛徽章:
- 0
|
可变参数的问题
给你个例子:
void Write_Log( const char *format, ... )
{
char *cp_File = "domain_modify.log";
FILE *fp;
char cp_WriteInfo[ 255 ] = { 0 };
va_list otherarg;
if(( fp = fopen( cp_File, "a" )) == NULL )
{
printf( "Open file[%s] error\n", cp_File );
return;
}
memset( cp_WriteInfo, 0x00, 255 * sizeof( char ) );
va_start( otherarg, format );
vsprintf( cp_WriteInfo, format, otherarg );
va_end( otherarg );
//printf( "cp_WriteInfo = [%s]\n", cp_WriteInfo );
if( fputs( cp_WriteInfo, fp ) == EOF )
{
printf( "Write Log error!\n" );
}
fclose( fp );
}
调用时
Write_Log( "[RIGHT] omain[%s] info equal to userbox info!\n\n", pc_DomainName );
和printf一样 |
|