Im writing a code that requires the input and output of a file which is typed on the command line. the output file would append or overwritten if it exists. im having difficulty running this as everytime i ran it the program crashes. and i hve already tried debugging it and it would say segfault.. any tips would be appreciated
return 0;
}
void creating_array(string* &list, int argc, char **argv)
{
list = new string[argc];
for (int i = 1; i <= argc ; ++i)
list[i] = argv[i];
}
void find_1(string *list, int argc, string in_file_name,string what )
{
vector<int> who;
for(int i = 0; i < argc; ++i)
if(list[i].find(what) < string::npos)
who.push_back(i);
if(who.size() == 0)
cout<<"The word " << what << " does not appear on the command line"<<endl;
else
{
cout<< what <<" is in these arguments from the command line:"<<endl;
for(int i = 0; i < who.size();++i)
{
cout<<"argv["<<i<<"] = " <<list[who[i]]<<endl;
list[who[i]] = in_file_name;
}
}
}
void find_2(string *list, int argc , string out_file_name, string what)
{
vector<int> who;
for(int i = 0; i < argc; ++i)
if(list[i].find(what) < string::npos)
who.push_back(i);
if(who.size() == 0)
cout<<"The word " << what << "does not appear on the command line"<<endl;
else
{
cout<< what <<" is in these arguments from the command line:"<<endl;
for(int i = 0; i < who.size();++i)
{
cout<<"argv["<<i<<"] = " <<list[who[i]]<<endl;
list[who[i]] = out_file_name;
}
}
}
inputfile.open(in_file_name.c_str());
cout << "Does the output file exist? (Press y for yes or n for no) " << endl;
cin >> seven[1];
if((seven[1] == 'y' )|| (seven[1] == 'Y'))
{
cout << "Enter /a to append, /e to overwrite, /o to quit and /r to reenter" << endl;
cin >> answerz;