Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8083643
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:32:22+00:00 2026-06-05T17:32:22+00:00

I have a program that encrypts files, but adds the extension .safe to the

  • 0

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”

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.

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

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);

I’m sure I’m missing something obvious, but if this approach doesn’t work, I’m looking for any simple method.

Edited to add:
(copied by moderator from poster’s response to K-ballo)

Thanks everyone. I took the std::string approach and found this to work:

Decrypt(myFile); 
string str = myFile; 
size_t pos = str.find(".safe"); 
str.replace(pos,5,""); 
rename(myFile, str.c_str());
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T17:32:23+00:00Added an answer on June 5, 2026 at 5:32 pm

    For what you want to do, simply changing the strncpy line to this will work:

    *newFile = '\0';
    

    This would still have problems if the filename contains an early .safe (like in file.safest.txt.safe), or if it does not contain the substring .safe at all. You would be better of searching from the end of the array, and making sure you do find something.

    This seems like a better approach (although in C++ it would be better to just go with std::string):

    char* filename = ...;
    size_t filename_length = strlen( filename );
    int safe_ext_pos = filename_length - 5; // 5 == length of ".safe"
    if( safe_ext_pos > 0 && strcmp( ".safe", filename + safe_ext_pos ) == 0 )
        filename[ safe_ext_pos ] = '\0';
    

    This is the std::string version of the code:

    std::string filename = ...;
    int safe_ext_pos = filename.length() - 5; // 5 == length of ".safe"
    if( safe_ext_pos > 0 && filename.compare( safe_ext_pos, 5, ".safe" ) == 0 )
        filename.erase( safe_ext_pos );
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program that looks something like this: public partial class It {
I have a PHP program that encrypts a PDF file into .xxx file this
I have a program that works with a variety of files on both the
I've written an encryption program that encrypts and decrypts selected files using a user-entered
I am creating a program that encrypts/hashs messages I have a list that contains
I have a program that reads server information from a configuration file and would
We have a program on our AS400 that takes in a number, encrypts it
I have program that requires Python 3, but I develop Django and it uses
I have a program that reads from a file that grabs 4 bytes from
I have a program in C++ that uses the cryptopp library to decrypt/encrypt messages.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.