Thread: Changing out_filename based of input

  1. #1
    Registered User
    Join Date
    Jan 2021
    Posts
    1

    Changing out_filename based of input

    Hi everyone, In my exam I've been given a task to read list from file and to create another file which would be output file. In the task it says that out_filaname should be changed based on input(in this specific case if I type "./task USA Friends 1994" as my call of program it should create file named USA.txt) So basicly whichever country I put in call, program should create country.txt file. How do I code that part of my program?

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,223
    You need to construct the filename from the command line argument, e.g., by creating an array of char large enough to hold the result, then copying the command line argument followed by ".txt".
    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

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Create strings based on input int?
    By omaralqady in forum C Programming
    Replies: 6
    Last Post: 03-02-2008, 11:14 AM
  2. Input-based permutation
    By TmX in forum C Programming
    Replies: 1
    Last Post: 11-20-2006, 04:30 AM
  3. Binary based input
    By DonW in forum C Programming
    Replies: 2
    Last Post: 09-21-2004, 12:43 AM
  4. changing 9x progs to nt based
    By scott27349 in forum A Brief History of Cprogramming.com
    Replies: 13
    Last Post: 02-12-2003, 05:08 PM
  5. Action Based On User Input
    By Stealth in forum C++ Programming
    Replies: 2
    Last Post: 10-03-2001, 05:38 AM

Tags for this Thread