Basically, I need to create a program that asks user to enter the number of input files, input filenames and output filename. Next, every line of the input files respectively are to be concatenated with a tab between each data. For example,
Inputs:
Your
My
Her
Dog
Cat
Wolf
Cute
Happy
Sad
Output:
Your "\t" Dog "\t" Cute
My "\t" Cat "\t" Happy
Her "\t" Wolf "\t" Sad
For 2 input files only, my code works fine:
#include <iostream>
#include <fstream>
#include <string>
using namespace std;
Do you have an upper limit for what the user is allowed to type in? E.g. is the user allowed to say "I have 1000 input files" and you have to accept it? Or can you tell the user "Nope, you get 50 and that's final."? Because the answer to this question makes a big difference.
constchar *cstr[100];
//...
for (int i = 0; i < n; i++) {
cstr[i] = inputFilename[i].c_str();
}
First, you don't need to do this. Second, you should never do this - .c_str() is only temporary and storing a pointer to it is no good. Just don't do it ;)
Also, I wasn't thinking properly when I asked about the max - first I should have asked if you are allowed to/know how to dynamically allocate arrays with a user-defined size. You can ask how many files first and then allocate the array when you know the size.