-
need advice
Hello i need some advice here to write my program in c language.
Let say my filename is : log.txt
My file "log.txt" contains data like this:
!!Begin
Source bserver:bmp_spool:the, Job 80c481ac001f6b07, Inst 80c481ac001f6b07
Title BP Page 003 Date 070402 Black 3
Action Finished Transmit, Ok Date Fri Apr 5 00:02:05 SGT 2002
(2) Source Queue = Ajil_Tabloid
(1) Destination = ajil:ajil1:bmp_spool:the
(3) Dest Queue = Futuro Tabloid
Transmitting to ajil:ajil1:bmp_spool:the
!!End
!!Begin
Source bserver:bmp_spool:the, Job 80c481ac001f6b0f, Inst 80c481ac001f6b0f
Title BP Page 004 Date 070402 Cyan 4
Action Started Transmit, Ok Date Fri Apr 5 00:02:05 SGT 2002
(2) Source Queue = Ajil_Tabloid
(1) Destination = ajil:ajil1:bmp_spool:the
(3) Dest Queue = Futuro Tabloid
Transmitting to ajil:ajil1:bmp_spool:the
!!End
!!Begin
Source bserver:bmp_spool:the, Job 80c481ac001f6b3d, Inst 80c481ac001f6b63
Title BP Page 010 Date 070402 Magenta 10
Action Finished Transmit, Ok Date Fri Apr 5 00:02:12 SGT 2002
(2) Source Queue = Prai_Tabloid
(1) Destination = prai:prai1:bmp_spool:the
(3) Dest Queue = Futuro Tabloid
Transmitting to prai:prai1:bmp_spool:the
!!End
I need to write c program and process , give me output like this in output file:
Title :BP Page 003 Date 070402 Black 3
Action: Finished Transmit
Time: 5 00:02:05
Misc: (3) Dest Queue = Futuro Tabloid
Title :BP Page 004 Date 070402 Cyan 4
Action: Started Transmit
Time: 5 00:02:05
Misc: (3) Dest Queue = Futuro Tabloid
Title:Title BP Page 010 Date 070402 Magenta 10
Action :Finished Transmit
Time: 5 00:02:12
Misc:(3) Dest Queue = Futuro Tabloid
Thank you. Any sample with sourcecode are appreciate.
sorry my english language not good.
-
Read the file, use strcmp() to check for the values you want, and output them in the format you want.
-
The file looks like it is formatted in a logical manner. You can simply write a program to test your input and only take what you want. Or assume that the file is formatted correctly and use that formatting to parse each line. Such as with getline and sscanf:
Input:
Action Finished Transmit, Ok Date Fri Apr 5 00:02:05 SGT 2002
Code:
getline ( INFILE, buffer );
sscanf ( buffer, "%*s %[^,] %*[^0123456789] %10c", actionString, timeString );
cout<< actionString <<"\n"<< timeString <<"\n";
Output:
Finished Transmit
5 00:02:05
-Prelude