I tried to find a solution but I did not find anything that solved my question.
I have a C++ program that receive a const char*
variable (filedata
) and the size (filesize
). The contents of this variable is a csv format. Each field is separated by ';'. The content is also dynamic, and may have more or less content, since this variable represents a set of logs. There is also a delimiter \n
to represent the line break.
Example 1 of filedata:
const char* filedata =
"1496843100;2017-06-07 13:45:00;000002D8;2800;0x23000CCD.VARIABLE67\n"
"1496843100;2017-06-07 13:45:00;000002D9;2800;0x23000CCD.VARIABLE68";
Example 2 of fildedata:
const char* filedata =
"1496843100;2017-06-07 13:45:00;000002D8;2800;0x23000CCD.VARIABLE67\n"
"1496843100;2017-06-07 13:45:00;000002D9;2800;0x23000CCD.VARIABLE68\n"
"1496843100;2017-06-07 13:45:00;000002DA;2800;0x23000CCD.VARIABLE69";
If you see the example 1 only have 2 lines, and the example 2 have 3 lines. I never know how many lines I have. I can have 2, 3, 200, 1000, etc. lines and the filedata
variable save all content.
So my objective is to receive this filedata
variable (I also have access to filesize) and for each line I need to parse the field 1 and 2 (timestamp and the data in normal format).
Expected output (for the example 2):
1496843100 2017-06-07 13:45:00
1496843100 2017-06-07 13:45:00
1496843100 2017-06-07 13:45:00
In example 2 I have 3 lines, so I need to iterate all lines and for each line parse the specific fields, very similar to the output.
After this i pick each parser fields and save to object list (This part is already implemented. I'm just having trouble parsing filedata
.