Need Help With Naming Output Files!!!

This is a discussion on Need Help With Naming Output Files!!! within the C++ Programming forums, part of the General Programming Boards category; I am writing a file to ask the user to input the name of the file that they want the ...

  1. #1
    Unregistered
    Guest

    Exclamation Need Help With Naming Output Files!!!

    I am writing a file to ask the user to input the name of the file that they want the data to be stored to. For example ...

    a:\\sample.txt

    I need to use a cout to ask what the file name they want to use is.... but i dont want to make them type in the entire path.. just the name....ie. "sample" and make it already add the a:\\ and the .txt Is this possible? If so, how do i do it?

    Any help would be greatly appreciated.

    Thanks

  2. #2
    Registered User cody's Avatar
    Join Date
    Sep 2001
    Posts
    86
    Hi.

    Yes, of course it's possible You'll need the basic string functions like strlen(), strcpy() or strcat(). (Have a look what the are doin')

    By using these functions you should be able to read in the name for the file and create a string, that will contain the complete path plus the filename.

    Some hints without code:

    1) read filename
    2) lenght of filename?
    3) create empty string with size =

    4 + ("a:\\") + lenght (filename) + 4 (".txt") + 1 "\0"

    4) append the "a:\\"
    5) append the filename
    6) append the ".txt"
    7) append the termination character "\0"

    enjoy
    cody
    #include "reallife.h"

  3. #3
    Registered User
    Join Date
    Oct 2001
    Posts
    2,934
    Or use function sprintf().

    char name[81], filename[81];

    cout << "Enter filename:";
    cin >> name;
    sprintf(filename,"a:\\%s.txt",name);
    cout << "filename:" << filename << endl;

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem reading tiff image files?
    By compz in forum C++ Programming
    Replies: 9
    Last Post: 10-30-2009, 05:17 AM
  2. Input and Output files
    By matrixhelp in forum C Programming
    Replies: 1
    Last Post: 03-10-2008, 03:07 AM
  3. Replies: 5
    Last Post: 02-25-2008, 06:35 AM
  4. Multiple Cpp Files
    By w4ck0z in forum C++ Programming
    Replies: 5
    Last Post: 11-14-2005, 02:41 PM
  5. Folding@Home Cboard team?
    By jverkoey in forum A Brief History of Cprogramming.com
    Replies: 398
    Last Post: 10-11-2005, 09:44 AM

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