Return filename from path
<p>What did I do wrong here?</p>

<p>call</p>

<pre><code>printf(filename(exename));
</code></pre>

<p>my function should return filename</p>

<pre><code>const char* filename(const string&amp; str)
{
  const char* path;
  size_t found;
  found=str.find_last_of("/\\");
  path = (str.substr(found+1)).c_str();

  cout &lt;&lt; str.substr(found+1); // ------------&gt; is name ok 

  printf("\n\n");
  printf(path); // ------------&gt; is name not ok random numbers
  printf("\n\n");
  return  path; // ------------&gt; is not ok random numbers
}
</code></pre>
