home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / s / snip1292.zip / FORMAT.C < prev    next >
C/C++ Source or Header  |  1992-12-26  |  1KB  |  56 lines

  1. /*
  2. **  FORMAT.C - Use DOS FORMAT to format a diskette
  3. **
  4. **  Original Copyright 1992 by Bob Stout as part of
  5. **  the MicroFirm Function Library (MFL)
  6. **
  7. **  This subset version is hereby donated to the public domain.
  8. */
  9.  
  10. #include <stdio.h>
  11.  
  12. enum {ERROR = -1, SUCCESS};
  13.  
  14. /*
  15. **  format
  16. **
  17. **  Formats a specified floppy disk with optional switches.
  18. **
  19. **  Parameters: 1 - Drive letter ('A', 'B', ...) to format
  20. **              2 - Formatting switches in FORMAT.COM format, e.g. "/4"
  21. **              3 - Volume label
  22. **
  23. **  Returns: SUCCESS or ERROR
  24. */
  25.  
  26. int format(char drive, char *switches, char *vlabel)
  27. {
  28.       char command[128], fname[13];
  29.       FILE *tmpfile;
  30.  
  31.       tmpnam(fname);
  32.       if (NULL == (tmpfile = fopen(fname, "w")))
  33.             return ERROR;                       /* Can't open temp file */
  34.       fprintf(tmpfile, "\n%s\nN\n", vlabel);
  35.       fclose(tmpfile);
  36.  
  37.       sprintf(command, "format %c: /V %s < %s > NUL", drive, switches, fname);
  38.  
  39.       system(command);
  40.  
  41.       remove(fname);
  42.  
  43.       return SUCCESS;
  44. }
  45.  
  46. #ifdef TEST
  47.  
  48. void main(void)
  49. {
  50.       int retval = format('a', "/4", "dummy_test");
  51.  
  52.       printf("format() returned %d\n", retval);
  53. }
  54.  
  55. #endif
  56.