C語言函式
函式簡介
函式名稱:_chdrive所屬庫名:direct.h
函式功能:改變當前的工作驅動器
函式原型:int _chdrive( int drive );
返回值:改變驅動器成功則返回0,否則返回-1
程式示例
下面的程式示例來自MSDN// crt_getdrive.c
// compile with: /c
// Illustrates drive functions including:
// _getdrive _chdrive _getdcwd
//
#include
#include
#include
#include
int main( void )
{
int ch, drive, curdrive;
static char path[_MAX_PATH];
// Save current drive.
curdrive = _getdrive();
printf( "Available drives are:\n" );
// If we can switch to the drive, it exists.
for( drive = 1; drive <= 26; drive++ )
{
if( !_chdrive( drive ) )
{
printf( "%c:", drive + 'A' - 1 );
if( _getdcwd( drive, path, _MAX_PATH ) != NULL )
printf( " (Current directory is %s)", path );
putchar( '\n' );
}
}
// Restore original drive.
_chdrive( curdrive );
}