<p>I am writing a C program in Linux.  Commands like execv() require a path in the form of a C string.  Is there a command that will return the current path in the form of a C-style string?</p>

[{'answer_id': 47071, 'author': 'John Millikin', 'author_id': 3560, 'author_profile': 'https://Stackoverflow.com/users/3560', 'pm_score': 5, 'selected': True, 'text': '<p><a href="http://www.opengroup.org/onlinepubs/009695399/functions/getcwd.html" rel="nofollow noreferrer">getcwd()</a>:</p>\n\n<blockquote>\n  <h3><em>SYNOPSIS</em></h3>\n\n<pre><code>#include &lt;unistd.h&gt;\n\nchar *getcwd(char *buf, size_t size);\n</code></pre>\n  \n  <h3><em>DESCRIPTION</em></h3>\n  \n  <p>The <em>getcwd()</em> function shall place an absolute pathname of the current working directory in the array pointed to by <em>buf, and return buf</em>. The pathname copied to the array shall contain no components that are symbolic links. The <em>size</em> argument is the size in bytes of the character array pointed to by the <em>buf</em> argument. If <em>buf</em> is a null pointer, the behavior of getcwd() is unspecified.</p>\n  \n  <h3><em>RETURN VALUE</em></h3>\n  \n  <p>Upon successful completion, <em>getcwd()</em> shall return the <em>buf</em> argument. Otherwise, <em>getcwd()</em> shall return a null pointer and set <em>errno</em> to indicate the error. The contents of the array pointed to by <em>buf</em> are then undefined....</p>\n</blockquote>\n'}, {'answer_id': 47073, 'author': 'Tanj', 'author_id': 4275, 'author_profile': 'https://Stackoverflow.com/users/4275', 'pm_score': -1, 'selected': False, 'text': '<p>You need to grab the environment variable PWD (present working directory).</p>\n<p>I\'m not sure what the library it is in, but it is a standard Linux header.</p>\n<p>I was thinking of <a href="http://www.opengroup.org/onlinepubs/000095399/functions/getenv.html" rel="nofollow noreferrer">getenv()</a> which would help if you also need to run system commands and need the various bin paths located in PATH.</p>\n'}, {'answer_id': 47074, 'author': 'Andreas Kraft', 'author_id': 4799, 'author_profile': 'https://Stackoverflow.com/users/4799', 'pm_score': 2, 'selected': False, 'text': '<p>This is <em>not</em> ANSI C:</p>\n\n<pre><code>#include &lt;unistd.h&gt;\n\nchar path[MAXPATHLEN];\ngetcwd(path, MAXPATHLEN);\nprintf("pwd -&gt; %s\\n", path);\n</code></pre>\n'}, {'answer_id': 47081, 'author': 'Commodore Jaeger', 'author_id': 4659, 'author_profile': 'https://Stackoverflow.com/users/4659', 'pm_score': 3, 'selected': False, 'text': '<p>The <strong>path</strong> argument to execv() is the path to the application you wish to execute, not the current working directory (which will be returned by getcwd()) or the shell search path (which will be returned by getenv("PATH")).</p>\n\n<p>Depending on what you\'re doing, you may get more mileage out of the system() function in the C library rather than the lower-level exec() family.</p>\n'}, {'answer_id': 47090, 'author': 'Paige Ruten', 'author_id': 813, 'author_profile': 'https://Stackoverflow.com/users/813', 'pm_score': 0, 'selected': False, 'text': "<p>If the path can be a relative path, you should be able to use '.' or './' as the path. I'm not sure if it will work, but you could try it.</p>\n"}]
['https://Stackoverflow.com/questions/47066', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/159/']