首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

一个有关问题,C语言中怎么打开一个未知的文件名

2012-03-20 
请教大家一个问题,C语言中如何打开一个未知的文件名?例如:U.AVL.BIL201.07010401.0.001.200612当中代表07

请教大家一个问题,C语言中如何打开一个未知的文件名?
例如:U.AVL.BIL201.07010401.0.001.200612
当中代表07年1月4日1时,周期为2006年12月,这两个时间会动态的变,我希望用fopen能打开它,请问如何用中间变量来过渡?当然是得用程序自动实现,而不是手工改名,谢谢各路高手指点:)  

第一次在此提问题,不胜感激

[解决办法]
char* get_file_name( char* buf )
{
time_t curtime;
struct tm* current;

time( &curtime );
current = localtime( &curtime );
sprintf( buf,
"U.AVL.BIL201.%02d%02d%02d%02d.0.001.%04d%02d ",
current-> tm_year % 100,
current-> tm_mon + 1,
current-> tm_mday,
current-> tm_hour,
current-> tm_mon == 0 ? current-> tm_year + 1900 - 1 : current-> tm_year + 1900 ,
current-> tm_mon == 0 ? 12 : current-> tm_mon );

return buf;

}

int main()
{
char filename[256];
FILE* f;
f = fopen( get_file_name( filename ), "r " );
if( f == NULl )
return 0;
/* ... */
fclose( f );
return 0;
}

热点排行
Bad Request.