Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • C

Idiom #106 Get program working directory

Assign to string dir the path of the working directory.
(This is not necessarily the folder containing the executable itself)

#include <unistd.h>
char *dir = getcwd(NULL, 0);

various C library implementations may or may not support using getcwd() this way, with a NULL buffer pointer that tells getcwd() to malloc(3) the returned buffer, which the caller should free(3).
with Ada.Directories; use Ada.Directories;
Dir : String := Current_Directory;

New implementation...
< >
programming-idioms.org