Thread: User defined output file name help!!!

  1. #1
    Registered User
    Join Date
    May 2015
    Posts
    6

    User defined output file name help!!!

    I was wondering if anyone could give reference to where I might find something on user defined output file names. I looked up different sites, even books but nothing explains how to do it. This is not for homework. I'm preparing for exams.
    This is an output function that I have. What I want is for "answerData.txt" to be renamed to any .txt file. I did read somewhere that there was a function called rename(), but I don't know how to implement that.

    Code:
    void file_output(linear_eq num){
      FILE* fp;
      fp = fopen("answerData.txt", "a");
      printf("%d %d %d\n", num.x, num.y, num.eq);
      fclose(fp);
      return;
    }
    Any help on this would be greatly appreciated. Thank you.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Do you want to rename "answerData.txt", or are you trying to open a file with a name specified by the user?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User
    Join Date
    May 2015
    Posts
    6
    I'm trying to output a file with a name specified by the user.

  4. #4
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Ah, then I suggest that you read a recent thread on How to create file with name the user wants?
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  5. #5
    Registered User
    Join Date
    May 2015
    Posts
    6
    Thank you so much!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. File names using a user defined name
    By KnightMan in forum C Programming
    Replies: 2
    Last Post: 04-11-2011, 08:28 PM
  2. user defined file I/O
    By montablac in forum C++ Programming
    Replies: 3
    Last Post: 06-05-2005, 04:26 AM
  3. Opening a user-defined file
    By mr_diss in forum C Programming
    Replies: 8
    Last Post: 02-28-2005, 03:47 PM
  4. need to read a User defined file during runtime
    By john_newbie in forum C Programming
    Replies: 8
    Last Post: 03-06-2004, 02:08 AM
  5. User Defined save file (help)
    By Unregistered in forum C++ Programming
    Replies: 9
    Last Post: 04-16-2002, 11:13 PM

Tags for this Thread