I'm working on a program for my cs class and it has to auto comment the code. We have set comments like //header , //function , //var , and we have to replace them with proper comments from a text file.
void openFiles(ifstream& input_file, ifstream& header_file, ifstream& function_file, ofstream& output_file)
{
//var
string input_file_name;
//var
string header_file_name;
//var
string function_file_name;
//var
string output_file_name;
cout << "Enter the file that you wish to add comments.\n";
cin >> input_file_name;
input_file.open(input_file_name.c_str());
if (input_file.fail())
{
cout << "ERROR FILE FAILED TO OPEN EXITING PROGRAM\n";
exit(EXIT_FAILURE);
}
header_file.open("header.txt");
if (header_file.fail())
{
cout << "ERROR FILE FAILED TO OPEN EXITING PROGRAM\n";
exit(EXIT_FAILURE);
}
function_file.open("function.txt");
if (function_file.fail())
{
cout << "ERROR FILE FAILED TO OPEN EXITING PROGRAM\n";
exit(EXIT_FAILURE);
}
cout << "Enter the file that you wish create.\n";
cin >> output_file_name;
output_file.open(output_file_name.c_str());
if (output_file.fail())
{
cout << "ERROR FILE FAILED TO OPEN EXITING PROGRAM\n";
exit(EXIT_FAILURE);
}
}
void add_coments(ifstream& input_file, ifstream& header_file, ifstream& function_file, ofstream& output_file)
{
//var
char content;
//used to hold the content of the file
//var
char header_content;
//used to hold the contents of the header file
//var
char function_content;
//used to hold the contents of the function file
//var
string line;
//used to compare the lines with either header, function, or var strings
//var
string header_line = "//header";
//used to check if the header comment is present and replaces it with the proper comment
//var
string function_line = "//function";
//used to check if the function comment is present and replaces it with the proper comment
//var
string var_line = "//var";
//used to check if the var comment is present and changes the var comment.
while (!input_file.eof())
{
if (strcmp(line.c_str(), header_line.c_str()) == 0)
{
header_file.get(header_content);
output_file << header_content;
}