C語言函式
函式簡介
函式名稱:_getdrive函式功能:返回當前的磁碟驅動器,1代表A盤,2代表B盤,依次類推
函式原型:int _getdrive( void );
所屬庫名:direct.h
程式示例
#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 );
}