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 151207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T09:24:47+00:00 2026-05-11T09:24:47+00:00

Not as in can’t find the answer on stackoverflow, but as in can’t see

  • 0

Not as in ‘can’t find the answer on stackoverflow’, but as in ‘can’t see what I’m doing wrong’, big difference!

Anywho, the code is attached below. What it does is fairly basic, it takes in a user created text file, and spits out one that has been encrypted. In this case, the user tells it how many junk characters to put between each real character. (IE: if I wanted to encrypt the word ‘Hello’ with 1 junk character, it would look like ‘9H(eal~l.o’)

My problem is that for some reason, it isn’t reading the input file correctly. I’m using the same setup to read in the file as I had done previously on decrypting, yet this time it’s reading garbage characters, and when I tell it to output to file, it prints it on the screen instead, and it seems like nothing is being put in the output file (though it is being created, so that means I’ve done something correctly, point for me!

code:

string start; char choice; char letter; int x; int y; int z; char c; string filename;  while(start == 'enc') {     x = 1;     y = 1;     cout << 'How many garbage characters would you like between each correct character?: ' ;     cin >> z;     cout << endl << 'Please insert the name of the document you wish to encrypt, make sure you enter the name, and the file type (ie: filename.txt): ' ;     cin >> filename;     ifstream infile(filename.c_str());     ofstream outfile('encrypted.txt', ios::out);      while(!infile.eof())     {         infile.get(letter);          while ((x - y) != z)                  {             outfile << putchar(33 + rand() % 94);             x++;             }         while((x - y) == z)         {             outfile << letter;             y = 1;             x = 1;         }     }     outfile.close();     cout << endl << 'Encryption complete...please return to directory of program, a new file named encrypted.txt will be there.' << endl;     infile.close();     cout << 'Do you wish to try again? Please press y then enter if yes (case sensitive).';     cin >> choice; 

What I pasted above the start of the while loop are the declaration variables, this is part of a much larger code that not only will encrypt, but decrypt as well, I left the decryption part out as it works perfectly, it’s this part I’m having an issue with.

Thanks in advance for the assist!

EDIT:: I’m using visual C++ express 2008, and it shoots back that there are no errors at all, nor any warnings.

IMPORTANT EDIT It turns out it is outputting to the file! However, it is outputting numbers instead of ascii characters, and it is also outputting the garbage character for the letter it should be. When it goes back to the ‘infile.get(letter)’, it doesn’t get a new character. So right now it seems to be the issues are 2 fold: 1) Printing numbers instead of ascii characters. 2) Using garbage instead of the actual character it should be getting.

Question Answered Found out the second part in the ‘Important Edit’ …it turns out if you name something test.txt…that means it is actually called test.txt.txt when you type it into a C++ program. Just goes to show it’s the tiny, minute, simple details that cause any program to go pooey. Thank you to George Shore. Your comment about the input file being in the wrong place is what gave me the idea to try the actual items name.

Thank you to everyone who helped with the answer!

  • 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. 2026-05-11T09:24:47+00:00Added an answer on May 11, 2026 at 9:24 am

    Further to the previous answers, I believe it’s because the file you wish to encrypt is not being found by the original code. Is it safe to assume that you’re running the code from the IDE? If so, then the file that is to be encrypted has to be in the same directory as the source.

    Also:

    outfile << putchar(33 + rand() % 94); 

    seems to be the source of your garbage to the screen; the ‘putchar’ function echoes to the screen whilst returning the integer value of that character. What is then going to happen is that number will be output to the file, as opposed to the character.

    Changing that block to something like:

    while ((x - y) != z)          {     c = (33 + rand() % 94);     outfile << c;     x++; } 

    should enable the code to run as you want it to.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 263k
  • Answers 263k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Ctrl + Shift + J in firefox, if you don't… May 13, 2026 at 12:02 pm
  • Editorial Team
    Editorial Team added an answer To answer your specific question: No, it cannot. See, for… May 13, 2026 at 12:02 pm
  • Editorial Team
    Editorial Team added an answer You just need to alias your subqueries: WITH x AS… May 13, 2026 at 12:02 pm

Related Questions

In order to apply a triggered animation to all ToolTip s in my app,
I want use html5's new tag to play a wav file (currently only supported
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on
I have a JSP page retrieving data and when single or double quotes are
I am currently running into a problem where an element is coming back from

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.