Thread: save as file name?

  1. #16
    I'm Back
    Join Date
    Dec 2001
    Posts
    556
    whats wrong in using gets...
    -

  2. #17
    Skunkmeister Stoned_Coder's Avatar
    Join Date
    Aug 2001
    Posts
    2,572
    You have no control with gets() over the number of chars read. This leads to buffer overrun errors. Someone said here, "so what, I'll just make the buffer bigger".To which the reply was doing that doesn't remove the bug,it just lessens its probability of occurring.Anytime that you need to use gets() you can use fgets() instead to get a certain number of chars from stdin and then you will never encounter the buffer overrun possibility.
    Free the weed!! Class B to class C is not good enough!!
    And the FAQ is here :- http://faq.cprogramming.com/cgi-bin/smartfaq.cgi

  3. #18
    adrive
    Guest
    thanks guys. i have another question:

    else if(answer==2)
    {

    cout<<"Define locationdiskdrive:\\folder\\filename) : ";
    cin>>location;

    strcat(location,".txt");
    write.open(location,ios:ut);

    bla bla bla
    }

    this actually works well, but if the user keys in a location which does not have a folder he keyed, then the file won't be saved.
    such as, c:\hello\hello where by "hello" folder doesn't exit on his harddrive

    so how can we solve this problem??

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Save a file with a name in a variable?
    By guriwashere in forum C Programming
    Replies: 2
    Last Post: 06-01-2009, 04:03 PM
  2. Need Help Fixing My C Program. Deals with File I/O
    By Matus in forum C Programming
    Replies: 7
    Last Post: 04-29-2008, 07:51 PM
  3. Post...
    By maxorator in forum C++ Programming
    Replies: 12
    Last Post: 10-11-2005, 08:39 AM
  4. Ask user to save file before exiting.
    By Bajanine in forum Windows Programming
    Replies: 3
    Last Post: 11-15-2004, 06:34 PM
  5. archive format
    By Nor in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 08-05-2003, 07:01 PM