Changing last 5 char of array
<p>I have a program that encrypts files, but adds the extension ".safe" to the end. So the end result is something like "file.txt.safe"</p>

<p>When I go to decrypt the file, the user enters the file name again: "file.txt.safe" which is saved to a char. Now I want to remove ".safe" and rename the file to its original name.</p>

<p>I have tried the following, but nothing seems to happen and there are no errors.</p>

<pre><code>Decrypt (myFile); //decrypts myFile

char * tmp = myFile;
char * newFile;
newFile = strstr (tmp,".safe");  //search tmp for ".safe"
strncpy (newFile,"",5);   //replace .safe with ""

rename (myFile, newFile);
</code></pre>

<p>I'm sure I'm missing something obvious, but if this approach doesn't work, I'm looking for any simple method.</p>

<p><strong>Edited to add:</strong>
<em>(copied by moderator from poster's response to K-ballo)</em></p>

<p>Thanks everyone. I took the std::string approach and found this to work: </p>

<pre><code>Decrypt(myFile); 
string str = myFile; 
size_t pos = str.find(".safe"); 
str.replace(pos,5,""); 
rename(myFile, str.c_str());
</code></pre>
