Originally Posted by
Codeplug
Thanks bud.
Here's the output function. All it really does is take the current time, parse the line of text, and output all of that to a text file:
Code:
void output (string currentline)
{
ofstream outfile("sal.log", ios::app); //opens file for append. if file does not exist, creates it.
//begin timestamp
time_t now;
struct tm *tm_now;
char buff[BUFSIZ];
now = time ( NULL );
tm_now = localtime ( &now );
strftime ( buff, sizeof buff, "%A, %x %X %p ", tm_now );
//endtimestamp
stringstream tokenizer(currentline); //parses currentline in preparation for writing
string token; //the token strings, separated by space
tokenizer >> token;
//outfile <<"^G";
outfile<< ( "%s", buff ); //outputs timestamp
int counter = 0; //counter to see if username is the token
while (tokenizer >> token) //writes as many tokens as there are
{
if (counter == 0) //if counter is 0, then it's on the username. username <= 8 characters
{
if (token.length() <= 8)
{
for(int c = 0; c < token.length(); c++) //outputs username
{
outfile << token[c];
}
for(int i = token.length(); i < 8; i++) //outputs padding, up to 8 characters
{
outfile << " ";
}
}
else
{
for(int i = 0; i < 8; i++) //if username > 8 characters, outputs first 8
{
outfile << token[i];
}
}
outfile << " "; //outputs space after username
}
else
{
for (int i = 0; i < token.length(); i++) //checks for " and does not output them
{
if (token[i] != '"')
{
outfile <<token[i];
}
}
outfile << " "; //writes a space at the end
}
counter++;
}
outfile <<endl; //goes to new line at the end of write
outfile.close();
}