Path: utzoo!attcan!uunet!wuarchive!emory!mephisto!mcnc!duke!romeo!drh From: drh@romeo.cs.duke.edu (D. Richard Hipp) Newsgroups: comp.sys.ibm.pc.programmer Subject: How to format an MS-DOS disk from C? Message-ID: <21090@duke.cs.duke.edu> Date: 30 Jul 90 13:19:30 GMT Sender: news@duke.cs.duke.edu Reply-To: drh@cs.duke.edu Organization: Duke University CS Dept.; Durham, NC Lines: 25 I need to format a floppy disk under program control (Turbo-C 1.5). Right now I am using the function listed below. It works, but relies on the presence of COMMAND.COM. It also does some needless disk I/O, and will not run on a single disk computer. Does anyone know how to format a floppy disk directly? Respond by mail and I will post a summary after two weeks. Thanx. /* ** Format a disk. "arg" is the argument to the DOS format command. ** Return false if a temporary file can not be opened. */ boolean format(char *arg){ FILE *fp; char cmd[200]; assert( strlen(arg)<160 ); if( (fp=fopen("temporar.y","w"))==0 ) return false; fprintf(fp,"\nn\n"); fclose(fp); sprintf(cmd,"format %s temporar.y2",arg); system(cmd); unlink("temporar.y"); unlink("temporar.y2"); return true; }