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 6.0 - <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() retrieves the full path name of the current working
    directory.  The path name cannot be longer than the integer specified
    by 'n', including a terminating NULL character, and is stored at
    'pathbuf'.

    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 uses
                malloc() to allocate a buffer of size 'n'. The buffer can
                be freed by using the return value of getcwd() (which is
                a pointer to the buffer) as the argument to free().

 Portability:   Not supported by ANSI standard.

   -------------------------------- 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