Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Borland C++ 2.x ( with Turbo C ) - <b>mktemp() create a unique file name</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 mktemp()                Create a Unique File Name

 #include   <dir.h>                      Required for declarations only

 char       *mktemp(template);
 char       *template;                   File name pattern

    mktemp() creates a unique file name by modifying 'template'.
    'template' has the form 'baseXXXXXX'. 'base' is the two-character
    part of the new file name supplied by the user.  The six Xs are place
    holders for the part supplied by mktemp().  'base' is saved and the
    six trailing Xs are replaced with two letters, a dot, and an
    extension of three letters.

       Returns:     A pointer to the modified template, if successful;
                    null value, if 'template' is badly formed or no more
                    unique names can be created.

         Notes:     mktemp() creates unique file names. It does not
                    create or open files.


   -------------------------------- Example ---------------------------------

    The following statements use mktemp() to create a unique file name
    and then use this name to open a new file.

           #include <dir.h>
           #include <fcntl.h>
           #include <sys\stat.h>

           char *template = "nfXXXXXX";
           char *fname;
           int fhndl;

           main()
           {
               fname = mktemp(template);
               fhndl = open(fname,O_CREAT,S_IREAD|S_IWRITE);
               printf("%s opened",fname);
               close(fhndl);
           }


See Also: fopen() open()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson