Like Tree1Likes
  • 1 Post By Subsonics

How do I prompt the user to choose the filename for a textfile output?

This is a discussion on How do I prompt the user to choose the filename for a textfile output? within the C Programming forums, part of the General Programming Boards category; As the title suggests? Code: printf("Please enter a filename for the output text file");scanf("%s", &output); FILE *FW; FW=fopen(C:\users\john\desktop\%s.text, output, "w"); ...

  1. #1
    Registered User
    Join Date
    Feb 2012
    Posts
    22

    How do I prompt the user to choose the filename for a textfile output?

    As the title suggests?

    Code:
    printf("Please enter a filename for the output text file");scanf("%s", &output);
    FILE *FW;
    FW=fopen(C:\users\john\\desktop\%s.text, output, "w");
    Is this along the right lines?

    Thanks

  2. #2
    Registered User
    Join Date
    Jan 2009
    Posts
    1,485
    No it's along these lines:

    Code:
    FW=fopen(output, "w");
    If the output entered doesn't contain a path it use your current working directory.
    cajones1990 likes this.

  3. #3
    Registered User
    Join Date
    Feb 2012
    Posts
    22
    Thought as much. Thanks

  4. #4
    Registered User
    Join Date
    Feb 2012
    Posts
    22
    If i want it to output a textfile rather than just a file which needs to be manually open with notepad is there a way?

  5. #5
    Registered User
    Join Date
    Feb 2012
    Posts
    22
    Quote Originally Posted by cajones1990 View Post
    If i want it to output a textfile rather than just a file which needs to be manually open with notepad is there a way?

    I've realised how this works now, however can anyone help by telling me if the filename already exists, how to prompt the user to type an alternative in?

    thanks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. User inputted filename
    By frankchester in forum C Programming
    Replies: 1
    Last Post: 12-02-2010, 08:52 AM
  2. Opening a textfile with user supplied filename
    By BeerGut in forum C++ Programming
    Replies: 4
    Last Post: 10-25-2009, 12:25 AM
  3. user defined path for FILENAME
    By drdigimon in forum C Programming
    Replies: 5
    Last Post: 10-12-2003, 06:04 PM
  4. Getting user input for filename loop
    By jpchand in forum C++ Programming
    Replies: 1
    Last Post: 09-16-2003, 06:37 AM
  5. letting the user type in the filename.
    By doampofo in forum C++ Programming
    Replies: 4
    Last Post: 04-16-2003, 09:29 PM

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