Connecting Tech Pros Worldwide Forums | Help | Site Map

Unpacking a file which has tokens

Newbie
 
Join Date: Oct 2009
Posts: 1
#1: Oct 21 '09
Hi,

can someone please help.

I have a file which look something like this:

Group=01|[*1]
List=01|[*2]|20090801||3|
Item=01005000|[*3]|20091001|000000005000||
Item=01015000|[*4]|20091001|000000015000||
Item=01035000|[*5]|20091001|000000035000||
List=02|[*6]|20090801|||
Item=02003500|[*7]|20091001|000000003500||[*8]
Item=02001500|[*9]|20091001|000000001500|1|[*8]
Item=02006000|[*10]|20091001|000000006000||[*8]
List=03|[*11]|20090801|||
Item=03002900|[*12]|20090801|000000002900||
Item=03003500|[*13]|20090801|000000003500||[*14]
Item=03009500|[*15]|20091001|000000009500||[*14]
Item=03011000|[*16]|20091001|000000011000||[*14]

[*1]
ENG=Prepaid
[*2]
ENG=CellC
[*3]
ENG=CEL0050
[*4]
ENG=CEL0150
[*5]
ENG=CEL0350
[*6]
ENG=MTN
[*7]
ENG=MTN0035
[*8]
ENG=DIal *110 and follow instructions
[*9]
ENG=MTN0015
[*10]
ENG=MTN0060
[*11]
ENG=Vodacom
[*12]
ENG=VOD0029
[*13]
ENG=VOD0035
[*14]
ENG=Dial 100* and follow instructions
[*15]
ENG=VOD0095
[*16]
ENG=VOD0110

I need to process the file and build menu's for each level... I'm battling to unpack the file though. I've tried a combination of strstr and strtok_r but am not getting very far. Anyone do anything of the kind before??

Thanks

Expert
 
Join Date: Mar 2008
Location: Naperville, Illinois U.S.
Posts: 831
#2: Oct 21 '09

re: Unpacking a file which has tokens


Do you have flexibility in how you unpack the file? I find it much easier to parse and filter text files with perl than with C.

Another possibility: does the text file use a standard format? If so, then perhaps parsing tools are available for that standard.

I suggest you extract a manageable subset from the text file and parse it manually to build up the menus you seek. This will insure that you have a solid understanding of what needs to be done.
Reply


Similar C / C++ bytes