Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Microsoft C - <b>getcwd() get path name of current working directory</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
getcwd()                 Get Path Name of Current Working Directory

 #include   <direct.h>                   Required for declarations only

 char       *getcwd(pathbuf,n);
 char       *pathbuf;                    Storage location of path name
 int        n;                           Maximum length of path name

    getcwd() gets the full path name of the current working directory and
    stores it at 'pathbuf'.  The path name (including terminating NULL
    character) cannot be any longer than the integer specified by 'n'.

    Returns:    A pointer to 'pathbuf' if successful, or NULL if there is
                insufficient memory to allocate 'n' bytes, or the path
                name is too long. A NULL return value causes 'errno' to
                be set to:

                ENOMEM:  Insufficient memory; malloc() couldn't allocate
                         'n' bytes (see below); or

                ERANGE:  Path name longer than 'n' characters.

      Notes:    If the 'pathbuf' argument is NULL, the function will
                automatically allocate a buffer of size 'n', using
                malloc(). The buffer can be freed by using the return
                value of getcwd() (which is a pointer to the buffer) as
                the argument to free().

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

    The following statement stores the name of the current working
    directory in 'pbuff':

           #include <direct.h>         /* getcwd declared */
           #include <stdlib.h>         /* perror declared */
           #include <stdio.h>          /* NULL defined   */

           char pbuff[30];

           main()
           {
               if (getcwd(pbuff,64) == NULL)
                   perror("unable to get path name");
               else
                   printf("%s",pbuff);
           }

See Also: chdir() mkdir() rmdir()

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