Skip to content

Instantly share code, notes, and snippets.

@sms420
Created June 14, 2009 22:50
Show Gist options
  • Save sms420/129855 to your computer and use it in GitHub Desktop.
Save sms420/129855 to your computer and use it in GitHub Desktop.
/* identify_date_string.cpp
reads from, line by line, a text file: INPUT.txt
adds a newline when it encounters a comma
removes commas and quotes from a CSV file
writes to, line by line, a temporary output text
file: DUDE_tmp.txt
then identifies the specific date objects in the
input text file and replaces them with the string
"DATE"
the next step in the program will be to add a date
manip object
*********************************************************/
#include<iostream>
#include<fstream>
#include<string.h>
using namespace std;
int main () {
string temp_string;// temporary string to hold line of data
ifstream inputFile ("INPUT.txt");
ofstream outputFile_tmp;
outputFile_tmp.open("DUDE_tmp.txt");
if (inputFile.is_open())
{
// scrap the first line of the text file
getline (inputFile,temp_string);
while (! inputFile.eof() )
{
// read line from INPUT.txt & copy to temp_string
getline (inputFile,temp_string);
// dynamically alocate enough memory for char array
char *a=new char[temp_string.size()+1];
// assign zero to the first value in the array
a[temp_string.size()]=0;
// copy data from temp_string into char array
memcpy(a,temp_string.c_str(),temp_string.size());
// write to outputFile, character, by character
for (int i = 0; i < temp_string.size(); i++)
{
// if the machine encounters a comma, add newline
if (strncmp (&a[i],",",1) == 0)
{ outputFile_tmp << endl; }
// if the machine encounters a quote, delete it
else if (strncmp (&a[i],"\"",1) == 0)
{ continue; }
else
{ outputFile_tmp << a[i]; }
}
outputFile_tmp << endl;
} // closes: while (! inputFile.eof() )
inputFile.close();
outputFile_tmp.close();
} // closes: if (inputFile.is_open())
// now that everything is clean, let's
// get down and dirty with parsing the
// date formatted object
ifstream inputFile_tmp ("DUDE_tmp.txt");
ofstream outputFile;
outputFile.open("OUTPUT.txt");
if (inputFile_tmp.is_open())
{
// scrap the first 2 lines of the text file
/* 1 */
getline (inputFile_tmp,temp_string);
// dynamically alocate enough memory for char array
char *pontz=new char[temp_string.size()+1];
// assign zero to the first value in the array
pontz[temp_string.size()]=0;
// copy data from temp_string into char array
memcpy(pontz,temp_string.c_str(),temp_string.size());
// write to outputFile, character, by character
for (int i = 0; i < temp_string.size(); i++)
{
outputFile << pontz[i];
}
outputFile << endl;
/* 2 */
getline (inputFile_tmp,temp_string);
// dynamically alocate enough memory for char array
char *wentz=new char[temp_string.size()+1];
// assign zero to the first value in the array
wentz[temp_string.size()]=0;
// copy data from temp_string into char array
memcpy(wentz,temp_string.c_str(),temp_string.size());
// write to outputFile, character, by character
for (int i = 0; i < temp_string.size(); i++)
{
outputFile << wentz[i];
}
outputFile << endl;
while (! inputFile_tmp.eof() )
{
// read line from temp input file & copy to temp_string
getline (inputFile_tmp,temp_string);
// dynamically alocate enough memory for char array
char *a=new char[temp_string.size()+1];
// assign zero to the first value in the array
a[temp_string.size()]=0;
// copy data from temp_string into char array
memcpy(a,temp_string.c_str(),temp_string.size());
// write to outputFile, character, by character
for (int i = 0; i < temp_string.size(); i++)
{
outputFile << "DATE";
break;
}
outputFile << endl;
/* 1 */
getline (inputFile_tmp,temp_string);
// dynamically alocate enough memory for char array
char *b=new char[temp_string.size()+1];
// assign zero to the first value in the array
b[temp_string.size()]=0;
// copy data from temp_string into char array
memcpy(b,temp_string.c_str(),temp_string.size());
// write to outputFile, character, by character
for (int i = 0; i < temp_string.size(); i++)
{
outputFile << b[i];
}
outputFile << endl;
/* 2 */
getline (inputFile_tmp,temp_string);
// dynamically alocate enough memory for char array
char *c=new char[temp_string.size()+1];
// assign zero to the first value in the array
c[temp_string.size()]=0;
// copy data from temp_string into char array
memcpy(c,temp_string.c_str(),temp_string.size());
// write to outputFile, character, by character
for (int i = 0; i < temp_string.size(); i++)
{
outputFile << c[i];
}
outputFile << endl;
/* 3 */
getline (inputFile_tmp,temp_string);
// dynamically alocate enough memory for char array
char *d=new char[temp_string.size()+1];
// assign zero to the first value in the array
d[temp_string.size()]=0;
// copy data from temp_string into char array
memcpy(d,temp_string.c_str(),temp_string.size());
// write to outputFile, character, by character
for (int i = 0; i < temp_string.size(); i++)
{
outputFile << d[i];
}
outputFile << endl;
/* 4 */
getline (inputFile_tmp,temp_string);
// dynamically alocate enough memory for char array
char *e=new char[temp_string.size()+1];
// assign zero to the first value in the array
e[temp_string.size()]=0;
// copy data from temp_string into char array
memcpy(e,temp_string.c_str(),temp_string.size());
// write to outputFile, character, by character
for (int i = 0; i < temp_string.size(); i++)
{
outputFile << e[i];
}
outputFile << endl;
/* 5 */
getline (inputFile_tmp,temp_string);
// dynamically alocate enough memory for char array
char *f=new char[temp_string.size()+1];
// assign zero to the first value in the array
f[temp_string.size()]=0;
// copy data from temp_string into char array
memcpy(f,temp_string.c_str(),temp_string.size());
// write to outputFile, character, by character
for (int i = 0; i < temp_string.size(); i++)
{
outputFile << f[i];
}
outputFile << endl;
} // closes: while (! inputFile_tmp.eof() )
inputFile_tmp.close();
outputFile.close();
} // closes: if (inputFile_tmp.is_open())
return 0;
} //** closes: main
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment