Thread: textfile 2

  1. #1
    Registered User
    Join Date
    Feb 2003
    Posts
    7

    Question textfile 2

    Part 1

    I need to write a program called Encrypt.cpp, which opens a text file. The name of this file is provided by the user. The program reads every character from this input file, adds 2 to the ASCII value of it, and prints the resulting character into a new file called output.dat.

    Part 2

    I then need to write a program called Decrypt.cpp, which opens a file containing encrypted data created using the scheme used in question 2. The decrypt program deciphers the text and displays it on the screen.

    Thanks

  2. #2
    Anti-Poster
    Join Date
    Feb 2002
    Posts
    1,401
    That's great! I need to write a game server for my MUD.
    If I did your homework for you, then you might pass your class without learning how to write a program like this. Then you might graduate and get your degree without learning how to write a program like this. You might become a professional programmer without knowing how to write a program like this. Someday you might work on a project with me without knowing how to write a program like this. Then I would have to do you serious bodily harm. - Jack Klein

  3. #3
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708

    Re: textfile 2

    Originally posted by davidnj732
    Part 1

    I need to write a program called Encrypt.cpp, which opens a text file. The name of this file is provided by the user. The program reads every character from this input file, adds 2 to the ASCII value of it, and prints the resulting character into a new file called output.dat.

    Part 2

    I then need to write a program called Decrypt.cpp, which opens a file containing encrypted data created using the scheme used in question 2. The decrypt program deciphers the text and displays it on the screen.

    Thanks


    That's nice, we all have *things to do*. Perhaps you could start by doing your own homework, posting specific questions, and above all, limiting posts on the same subject to a single thread.

    Thank you.
    Code:
    #include <cmath>
    #include <complex>
    bool euler_flip(bool value)
    {
        return std::pow
        (
            std::complex<float>(std::exp(1.0)), 
            std::complex<float>(0, 1) 
            * std::complex<float>(std::atan(1.0)
            *(1 << (value + 2)))
        ).real() < 0;
    }

  4. #4
    Registered User
    Join Date
    Nov 2002
    Posts
    82
    Here's a little snippet.

    Code:
    char c;
    FILE *ifp, *ofp;
    
    /*...some code here...*/
    
    ifp = fopen("myfile.txt", "r");
    ofp = fopen("output.dat", "w");
    
    /*...some more code...*/
    
    c = getc(ifp);
    c += 2;
    fprintf(ofp, "%c", c);
    
    /*...some more code...*/
    
    fclose(ofp);
    fclose(ifp);
    
    /*The End*/

  5. #5
    Redundantly Redundant RoD's Avatar
    Join Date
    Sep 2002
    Location
    Missouri
    Posts
    6,331
    How about instead of showing us a snippet and waiting for us to do it for you, you actually try and do it yourself or ask some questions.

  6. #6
    Registered User
    Join Date
    Nov 2002
    Posts
    82
    >>How about instead of showing us a snippet and waiting for us to do it for you, you actually try and do it yourself or ask some questions.<<

    You're confusing me bud Are your referring to me or to that newbie C++ programmer?

  7. #7
    napKINfolk.com napkin111's Avatar
    Join Date
    Apr 2002
    Posts
    310
    Rez, I think RoD thought you were the same people. I don't think you should have given him all that code though, lol

    //napKIN
    "The best way to get answers is to just keep working the problem, recognizing when you are stalled, and directing the search pattern.....Don’t just wait for The Right Thing to strike you – try everything you think might even be in the right direction, so you can collect clues about the nature of the problem."
    -John Carmack

  8. #8
    Registered User
    Join Date
    Nov 2002
    Posts
    82
    I was trying to give the little guy an idea

  9. #9
    Registered User
    Join Date
    Feb 2003
    Posts
    7
    thanks guys for you input. Just trying to learn something new. Professor gave us a challenge and I didn't have a clue how to begin or what I was doing. Still really a newbie. He gives us these challenges all the time.

  10. #10
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Rez, your code is C, with this being a C++ forum, I expect davidnj732 is writing C++, so I'm afriad your examples won't help.

    davidnj732: Start with a tutorial or two. Post code when you get stuck.
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  11. #11
    Registered User
    Join Date
    Nov 2002
    Posts
    82
    Well... I can't think of any other File I/O technique. Is there such a thing as an "entirely-different-from-C-that-is-unique-to-C++" File I/O routine?

  12. #12
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Originally posted by Rez
    Well... I can't think of any other File I/O technique. Is there such a thing as an "entirely-different-from-C-that-is-unique-to-C++" File I/O routine?
    http://www.cppreference.com/cppio.html
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

  13. #13
    Registered User
    Join Date
    Nov 2002
    Posts
    82
    Hey pretty neat!

  14. #14
    Registered User
    Join Date
    Nov 2001
    Posts
    70
    Code:
    :startover
    open a file
    read 1 charater
    convert it to acsii number
    add 2 to it
    convert it to a character
    if youve reached EOF goto done
    else jump startover
    :done
    write to file
    thats to encrypt it, if ya need more pseudo code to decrypt it, jsut ask, noone will (they shouldnt anyways) be writing code for you.
    "...since anyone who is anyone knows C..." -Peter Cellik

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Cin to textfile
    By Charlin in forum C++ Programming
    Replies: 8
    Last Post: 01-10-2008, 01:52 PM
  2. Delete string from textfile
    By beon in forum C Programming
    Replies: 1
    Last Post: 11-15-2006, 06:10 AM
  3. Read blank delimeted textfile
    By Sera7 in forum C Programming
    Replies: 5
    Last Post: 01-05-2006, 05:44 PM
  4. textfile questions
    By ReLiEnThAwK in forum C++ Programming
    Replies: 11
    Last Post: 08-07-2005, 06:48 PM
  5. getting the beginig of a line in a textfile
    By stormbringer in forum C Programming
    Replies: 1
    Last Post: 11-19-2002, 11:30 AM