Problem with some code

This is a discussion on Problem with some code within the C++ Programming forums, part of the General Programming Boards category; You have nine strings in your program. If you mean what type variable should you have, the answer is "string"....

  1. #16
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    You have nine strings in your program. If you mean what type variable should you have, the answer is "string".

  2. #17
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Code:
    std::string ms;
    ms = "string";
    std::cout << ms;

  3. #18
    Registered User
    Join Date
    Feb 2008
    Posts
    26
    I update the code. Is it a good layout?

  4. #19
    Registered User
    Join Date
    Oct 2001
    Posts
    2,129
    Looks good, except the outer switch could be just an if else.

    And what does password do?

  5. #20
    Registered User
    Join Date
    Feb 2008
    Posts
    26
    Password does nothing. I originally put it in there because I thought i needed it but it is unnecessary.

  6. #21
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,449
    Can I suggest this to you when you have time? It's good to know. You're making progress. But you could make a little progress in more than one area!
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  7. #22
    Registered User
    Join Date
    Feb 2008
    Posts
    26
    Hmm... So where in my code do you think I should work on spacing? The second switch should be more indented?

  8. #23
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,449
    Indentation levels are mostly inconsistent and 2 spaces is a tad too low. 4 spaces minimum I should recommend.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  9. #24
    Registered User
    Join Date
    Feb 2008
    Posts
    26
    Ah I see. Thank's, I dont know very much on code etiquet since I just started. What I envision for this program, which I am still working on, is a program which when started will ask for a master password and then will ask for how many passwords you want to save then ask for the name of each so like "Email" and then ask for the atucal password. Im currently looking up File I/O so I can figure out how to write to and create text files out of the program. Also, I was wonerding, Is there a way to encrypt files? Like say each of the passwords are stored in a file outside the program like a text file. Is there a way so that only the program could access the files so that not any one could just go in an open up the file.

  10. #25
    Internet Superhero
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    964
    Quote Originally Posted by A13W View Post
    Ah I see. Thank's, I dont know very much on code etiquet since I just started. What I envision for this program, which I am still working on, is a program which when started will ask for a master password and then will ask for how many passwords you want to save then ask for the name of each so like "Email" and then ask for the atucal password. Im currently looking up File I/O so I can figure out how to write to and create text files out of the program. Also, I was wonerding, Is there a way to encrypt files? Like say each of the passwords are stored in a file outside the program like a text file. Is there a way so that only the program could access the files so that not any one could just go in an open up the file.
    There are many algorithms for encrypting stuff, but some of them are quite complicated to implement. When you are done with this program i'd suggest you look up XOR-encryption, it's very easy to implement, it is often used for teaching C/C++ (So it's easy to find tutorials on it), but the security lacks a bit compared to other algorithms, like RSA or AES.

    Security is good enough for something like this i'd image though. Even though it is not invincible, XOR still takes alot of effort to get through, so if you just want to keep people out, it'll do fine..
    How I need a drink, alcoholic in nature, after the heavy lectures involving quantum mechanics.

  11. #26
    Registered User
    Join Date
    Feb 2008
    Posts
    26
    Yeah, thanks, Ill look into that. Im not like encrypting like SS numbers or stuff.

  12. #27
    Registered User
    Join Date
    Feb 2008
    Posts
    26
    Hm, would it be more logical to store all the passwords and password names in one file or is that hard to access and should be in all seperate files like:
    master_password.txt
    first_password.txt
    first_password_name.txt

  13. #28
    Registered User
    Join Date
    Feb 2008
    Posts
    26
    This is a code I guess i could use to edit the variables in outside files, tell me how it looks:
    Code:
    #include <iostream>
    #include <fstream>
    
    using namespace std;
    
    int input;
    std::string master_password;
    std::string first_password;
    std::string second_password;
    std::string third_password;
    std::string fourth_password;
    std::string first_password_name;
    std::string second_password_name;
    std::string third_password_name;
    std::string fourth_password_name;
    
    int main()
    {
        do {
        cout<<"\n";
        cout<<"1.Edit Master password.\n";
        cout<<"2.Edit First password name.\n";
        cout<<"3.Edit First password.\n";
        cout<<"4.Quit.\n";
        cout<<"What would you like to do: ";
        cin>> input;
    
    
        switch ( input) {
            case 1:
            {
                ofstream myfile ("master_password.txt");
                        cout<<"Enter the master password you would desire: ";
                        cin>> master_password;
                        myfile << master_password;
                        myfile.close();
                        input<< 0;
                break;
            }
            case 2:
            {
                ofstream fpnfile ("first_password_name.txt");
                        cout<<"\n";
                        cout<<"\n";
                        cout<<"Now enter the name of you first password i.e.'Email': ";
                        cin>>first_password_name;
                        fpnfile << first_password_name;
                        fpnfile.close();
                        input<< 0;
                break;
            }
            case 3:
            {
                ofstream fpfile ("first_password.txt");
                        cout<<"\n";
                        cout<<"\n";
                        cout<<"Now enter the atcual first password: ";
                        cin>>first_password;
                        fpfile << first_password;
                        fpfile.close();
                        input<< 0;
                break;
            }
        }
       } while ( input !=4 );
    }
    I know the do { isint spaced because It takes to much time.

  14. #29
    C++まいる!Cをこわせ! Elysia's Avatar
    Join Date
    Oct 2007
    Posts
    22,449
    Quote Originally Posted by A13W View Post
    I know the do { isint spaced because It takes to much time.
    Not if you have a proper editor. It's not etiquette, as the article explains it very well. It's about code readability. It helps others understand your code and it helps you avoid bugs.
    For example, in Visual Studio, this is a cinch to do. Just select all the code and press tab and all the text you selected will be indented once more. That goes to show it's not difficult. There may be a similar button in other IDEs as well.
    Quote Originally Posted by Adak View Post
    io.h certainly IS included in some modern compilers. It is no longer part of the standard for C, but it is nevertheless, included in the very latest Pelles C versions.
    Quote Originally Posted by Salem View Post
    You mean it's included as a crutch to help ancient programmers limp along without them having to relearn too much.

    Outside of your DOS world, your header file is meaningless.

  15. #30
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,473
    Quote Originally Posted by Elysia View Post
    Not if you have a proper editor. It's not etiquette, as the article explains it very well. It's about code readability. It helps others understand your code and it helps you avoid bugs.
    For example, in Visual Studio, this is a cinch to do. Just select all the code and press tab and all the text you selected will be indented once more. That goes to show it's not difficult. There may be a similar button in other IDEs as well.
    Moreover in VS you select all the text, press Alt+F8 and your code is autoformatted for you
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

Page 2 of 3 FirstFirst 123 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Code problem
    By sybariticak47 in forum C++ Programming
    Replies: 9
    Last Post: 02-28-2006, 10:50 AM
  2. Problem with game code.
    By ajdspud in forum C++ Programming
    Replies: 5
    Last Post: 02-14-2006, 05:39 PM
  3. problem with selection code
    By DavidP in forum Game Programming
    Replies: 1
    Last Post: 06-14-2004, 01:05 PM
  4. Replies: 5
    Last Post: 12-03-2003, 04:47 PM
  5. Help with code for simple Y2K problem
    By Mule in forum C++ Programming
    Replies: 3
    Last Post: 03-05-2003, 11:53 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21