Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
program used to split up transcription files
// Name: Marty Miller
// Program: This program fixes a transcription file that needs special formatting
/*
Purpose: We will be dealing with file input and output, as well as character
handling. It separates transcripts into separate files by pages.
*/
#include <fstream>
#include <iostream>
#include <string.h>
using namespace std;
void doc_fix(ifstream& input, string oFilename);
int main()
{
ifstream i_stream;
string filename, oFilename;
cout << "Hello! This program takes a text file and formats it to be uploaded\n"
<< "into ContentDM as a transcript to a compound object.\n\n";
cout << "Please input the name of the file you want to format WITHOUT the extension.\n";
cin >> oFilename;
filename = oFilename + ".txt";
i_stream.open(filename.c_str());
if(i_stream.fail())
{
cout << "The output file failed to open and the program cannot continue. Good-bye.\n\n";
system("PAUSE");
return 0;
}
doc_fix(i_stream, oFilename);
system("PAUSE");
return EXIT_SUCCESS;
}
void doc_fix(ifstream& input, string oFilename)
{
ofstream output;
string filename, pnum;
char num[4], current;
int error_count = 0, pagecount = 0, pagenum = 0;
// set the pagenumber to one for the first page
pagenum = 1;
// change this to a char so that it can be used to make a file name
itoa(pagenum,num,10);
// change it to a string so it can be concatenated to the file name
pnum = num;
// create the new output file name
filename = oFilename + "p" + pnum + ".txt";
// open this stream and create the .txt file needed
output.open(filename.c_str());
// check to see if the file failed to open
if(output.fail())
{
cout << "The output file failed to open and the program cannot continue. Good-bye.\n\n";
system("PAUSE");
exit(1);
}
input.get(current);
output << current;
// Work through the entire file, checking for certain characters
do
{
// Get each letter of the input file...
input.get(current);
// check to see if the character makes it the end of the page
// marked by a [Page]
if(current == '[') // find the first part
{
input.get(current); // get the next letter
if(current == 'P') // check if it follows the path
{
// if it is the end of the page, close the currently opened file
output.close();
// increase the page number by oen
pagenum++;
// change the int to a char so it can be used in the file name
itoa(pagenum,num,10);
// store the char into a string so it can be concatenated
pnum = num;
// clear the string so that the file names do not stack
filename.clear();
// make the new file name with the appropriate page number
// and extension
filename = oFilename + "p" + pnum + ".txt";
// open this file stream and create the appropriate .txt file
output.open(filename.c_str());
// check to see if
if(output.fail())
{
cout << "The output file failed to open and the program"
<< " cannot continue. Good-bye.\n\n";
system("PAUSE");
exit(1);
}
// output the file that was lost due to testing
output << "[";
}
}
output << current;
}while(!input.eof()); // Check to see if the end of the file has been reached
output.close();
// Notify user of all of all actions
cout << "\n\nThere were a total of " << pagenum << " pages.\n\n"
<< "Thank you for using Marty's transcription correction service!\n"
<< "Good-bye!\n\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.