views:

16

answers:

1

Hi all I was wondering how (if possible) to change to an external HDD in C. I am writing a program that works with an external HDD.

Thanks much, Mr. Man

+2  A: 

Be wary of changing directory within a program - all that's usually needed is to open the files on the external device without actually changing directory to it.

However, on both Windows and Unix, the basic answer is via a 'change directory' operation. On Unix-like platforms, that is the 'chdir(2)' system call; your program should specify the name of the directory where the external hard disk is mounted, and then relative pathnames will write to appropriate locations on the disk (subject to the path name not containing too many "../" sequences).

On Windows, you would need to ensure you specify the drive letter as well as the path on the hard drive.

Jonathan Leffler