home *** CD-ROM | disk | FTP | other *** search
/ Liren Large Software Subsidy 7 / 07.iso / c / c023 / 1.img / PROGRAMS / GETFNAME.C < prev    next >
Encoding:
C/C++ Source or Header  |  1987-11-05  |  1.3 KB  |  53 lines

  1. /************************************************************************
  2.  *
  3.  * getfname.c  --  prompt user for name of existing file.
  4.  *
  5.  */
  6.  
  7. #include "cbtree.h"
  8. /* btfio.h *must* be included when bt_open() is used */
  9. #include "btfio.h"
  10.  
  11. getfname(argc, argv, ext, filename)
  12. int   argc;
  13. char *argv[];
  14. char *ext;     /* default extension to add */
  15. char *filename;   /* where to put copy of valid filename */
  16. {
  17.    int  fdidx, i;
  18.  
  19.    if (argc > 1)
  20.       strcpy(filename, argv[1]);
  21.    else
  22.    {
  23.       printf("\n\n        %s","Enter File Name (xxxxxxxx.xxx) ==> ");
  24.  
  25.       gets(filename);
  26.    }
  27.  
  28.    repeat
  29.    {
  30.       for (i = 0; filename[i] != '\0'; ++i)
  31.       {
  32.          if (filename[i] == '.')   /* if extension was specified, use it */
  33.             break;
  34.       }
  35.       if (filename[i] == '\0')
  36.       {
  37.          *(filename + i) = '.';   /* give it the default */
  38.          strcpy(filename + i + 1, ext);   /* give it the default */
  39.       }
  40.  
  41.       if((fdidx = bt_open(filename,O_RDWR)) == ERR)
  42.       {
  43.          printf("\nLOOKHDR: can't open file '%s'", filename);
  44.          printf("\n\n        %s","Enter File Name (xxxxxxxx.xxx) ==> ");
  45.          gets(filename);
  46.          if (*filename == NUL  || toupper(*filename) == 'X')
  47.             exit(0);
  48.       }
  49.    }
  50.    until(fdidx != ERR);
  51.    return (fdidx);
  52. }
  53.