Remove everything before last forward-slash (including that slash) in a C char array
<p>I have a char array called <code>arg</code>. <code>arg[0]</code> is the path to a file. I do not know the exact path, so lets just say it's <code>/path/to/file</code>. I do not want to know the full path, I just want to know the filename (<code>file</code> in this case). So how can I remove everything before the last forward slash (including that slash), resulting in <code>"file"</code>, instead of <code>"/path/to/file"</code>, or <code>"alternatefile"</code>, instead of <code>"/alternatepath/to/alternatefile"</code>?</p>

<p>Here is my code:</p>

<pre><code>#include &lt;stdio.h&gt;
int main(int argc, char *argv[]) {
    char *arg[] = argv;
    // This is where I need code to trim everything before the last forward-slash
    printf("%s\n", arg[0]);
}
</code></pre>

<p>So I need something like <code>arg[0] = strtrm(everythingbefore, "/", arg[0]);</code></p>