Thread: Dynamic directory names

  1. #16
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    There is a precise order to things.

    You're basically expecting this to work
    a = myvar + 2;
    cin >> myvar; // type in 5
    // here you're expecting a to be 5 + 2, and it simply isn't going to happen.

    Read strings in, THEN build them up with your other data.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  2. #17
    Registered User
    Join Date
    Oct 2006
    Posts
    118

    Question

    Like I said, I'm somewhat new to this, so if theres something that should be placed different, please tell me (I'm not taking any classes, so no, I'm not trying to cheat).

    Here's what I've got after some minor modification:

    Code:
    #include <iostream>
    #include <fstream>
    #include <sys/stat.h>
    #include <unistd.h>
    #include <stdio.h>
    
    using namespace std;
    
    int main()
    {
        std::string newusername;
        std::string newuserpassword;
    
        {
         
        cout<<"Please enter a user name to use (one word only, 30 letters): ";
        cin>>newusername;
        cin.ignore();
        
        cout<<"\n"<<newusername<<" is now being used as your username.\n\n";
        cout<<"Enter a password to use for "<<newusername<<"'s account: ";
        cin>>newuserpassword;
        cin.ignore();
        
        cout<<"\nPlease wait while your account ('"<<newusername<<"') is created...";
        cout<<"\n\nCreating User Folder...";
        
        mkdir("C:/Program Files/MUMS/");
        std::string newDir="C/Program Files/MUMS/"+newusername;
        mkdir(newDir.c_str());
        
        cout<<"\nCreating Username File...";
        
        std::string unfile="C:/Program Files/MUMS/";
        unfile+=newusername;
        unfile+="/username.mums";
        
        ofstream usernamecreate;
        usernamecreate.open(unfile.c_str());
        usernamecreate<<newusername<<endl;
        usernamecreate.close();
            
        cout<<"\n"<<newusername<<"'s User Name file successfully created!...";
        
        cout<<"\nCreating Password File...";
    
        std::string pfile="C:/Program Files/MUMS/";
        pfile+=newusername;
        pfile+="/password.mums";
        
        ofstream userpasswordcreate;
        userpasswordcreate.open(pfile.c_str());
        userpasswordcreate<<newuserpassword<<endl;
        userpasswordcreate.close();
        
        cout<<"\n"<<newusername<<"'s Password saved successfully!...";
        
        cout<<"\n\nDone!";
        cout<<"\n\nYour User Name is '"<<newusername<<"' and your password is '"<<newuserpassword<<"'.\n"
              "Make sure that you know these, as there is no way of retirieving\nthis information.";
        cin.get();
        }
    }

  3. #18
    Registered User
    Join Date
    Oct 2006
    Posts
    118
    Can anybody at least give me a clue...?

    FlyingIsFun1217

  4. #19
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> Can anybody at least give me a clue...?
    Do you have a question?

  5. #20
    Reverse Engineer maxorator's Avatar
    Join Date
    Aug 2005
    Location
    Estonia
    Posts
    2,318
    Quote Originally Posted by Daved
    >> Can anybody at least give me a clue...?
    Do you have a question?
    I think his question is "What should I do?"
    "The Internet treats censorship as damage and routes around it." - John Gilmore

  6. #21
    Registered User
    Join Date
    Oct 2006
    Posts
    118
    Precisely

    I have looked and looked, but just can't see where I screwed up...

    FlyingIsFun1217

  7. #22
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    What is the problem? What is not working? Your original problem is fixed, so all I see is code that looks fine at first glance. Does it fail to compile? Does it fail to do what you want it to? Explain what you want help with.

  8. #23
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    Well I did this
    Code:
        std::string newDir="C/Program Files/MUMS/"+newusername;
        int err = mkdir(newDir.c_str());
        cout << err << endl;
    Which printed
    Creating User Folder...-1

    So I looked at what you were doing, and pretty soon spotted something missing
    Code:
    std::string newDir="C:/Program Files/MUMS/"+newusername;
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  9. #24
    Registered User
    Join Date
    Oct 2006
    Posts
    118
    Wow... talk about feeling really stupid!

    Thanks everybody for helping me on this... I have now completed a somewhat large chunk of my very large (to me) planned program!

    Thanks again to everybody who was patient to me

    FlyingIsFun1217

  10. #25
    Registered User
    Join Date
    Oct 2006
    Posts
    118
    Here we go again (bump...)

    I've now tried to combine this with another program that I have, basically to encrypt and decrypt a password for saving in a file.

    Heres what I have:

    Code:
    #include <iostream>
    #include <fstream>
    #include <sys/stat.h>
    #include <unistd.h>
    #include <stdio.h>
    
    using namespace std;
    
    int main()
    {
        std::string newusername;
        std::string newuserpassword;
    
        {
    
        cout<<"Please enter a user name to use (one word only, 30 letters): ";
        cin>>newusername;
        cin.ignore();
    
        cout<<"\n"<<newusername<<" is now being used as your username.\n\n";
        cout<<"Enter a password to use for "<<newusername<<"'s account: ";
        cin>>newuserpassword;
        cin.ignore();
    
        cout<<"\nPlease wait while your account ('"<<newusername<<"') is created...";
        cout<<"\n\nCreating User Folder...";
    
        mkdir("C:/Program Files/MUMS/");
        std::string newDir="C:/Program Files/MUMS/"+newusername;
        mkdir(newDir.c_str());
    
        cout<<"\nCreating Username File...";
    
        std::string unfile="C:/Program Files/MUMS/";
        unfile+=newusername;
        unfile+="/username.mums";
    
        ofstream usernamecreate;
        usernamecreate.open(unfile.c_str());
        usernamecreate<<newusername<<endl;
        usernamecreate.close();
    
        cout<<"\n"<<newusername<<"'s User Name file successfully created!...";
    
        cout<<"\nCreating Password File...";
    
        std::string pfile="C:/Program Files/MUMS/";
        pfile+=newusername;
        pfile+="/password.mums";
    
        ofstream userpasswordcreate;
        userpasswordcreate.open(pfile.c_str());
    
        void encode(std::string& pass) {
    
        for (unsigned int i = 0; i != pass.size(); ++i) {
            pass.at(i) += 7;
            }
        }
    
        encode(newuserpassword);
    
        userpasswordcreate<<newuserpassword<<endl;
        userpasswordcreate.close();
    
        void decode(std::string& code) {
    
        for (unsigned int i = 0; i != code.size(); ++i) {
            code.at(i) -= 7;
            }
        }
    
        decode(newuserpassword);
    
        cout<<"\n"<<newusername<<"'s Password saved successfully!...";
    
        cout<<"\n\nDone!";
        cout<<"\n\nYour User Name is '"<<newusername<<"' and your password is '"<<newuserpassword<<"'.\n"
              "Make sure that you know these, as there is no way of retirieving\nthis information.";
        cin.get();
        }
    }
    Thanks for the help,

    FlyingIsFun1217

    ------------EDIT------------
    Nevermind, I moved the voids...

    I really have to start thinking of these things before I post...

    FlyingIsFun1217
    Last edited by FlyingIsFun1217; 11-11-2006 at 05:19 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Couple errors please help :-D
    By JJJIrish05 in forum C Programming
    Replies: 9
    Last Post: 03-06-2008, 02:54 AM
  2. Adding a directory to a dynamic library path
    By vivharv in forum Windows Programming
    Replies: 3
    Last Post: 09-20-2007, 07:09 AM
  3. traverse a directory and list all file names?
    By George2 in forum C Programming
    Replies: 3
    Last Post: 08-24-2006, 06:18 PM
  4. File names in a directory
    By gotclout in forum C++ Programming
    Replies: 6
    Last Post: 06-28-2006, 06:13 AM