Previous Thread
Next Thread
Print Thread
strtok #19041 12 Jul 11 10:13 PM
Joined: Jun 2001
Posts: 153
O
OmniLedger - Tom Reynolds Offline OP
Member
OP Offline
Member
O
Joined: Jun 2001
Posts: 153
Using multiple calls to XCALL STRTOK to parse STRING1 of items ITEM1 ITEM2 ITEM3 ITEM4 separated by spaces.

The processing of ITEM2 involves a single call to STRTOK to parse a completely different STRING2 with items separated by cr.

On the next call to STRTOK to get ITEM3 nothing is returned as if STRING1 had been completed.

The multiple calls to STRTOK and the single call do not involve any of the same variables.

Is this a bug or by design?

Barry

Re: strtok #19042 13 Jul 11 04:30 AM
Joined: Jun 2001
Posts: 11,945
J
Jack McGregor Online Content
Member
Online Content
Member
J
Joined: Jun 2001
Posts: 11,945
Ugh. I believe the problem here is within the standard C library implementation of the underlying strtok() function, which uses an internal static variable to keep track of the position within the string being parsed. (A-Shell's STRTOK.SBR wraps around the OS version of strtok(), making multiple calls to peel off all the parameters passed.)

The only workaround I can think of would be to completely parse out the STRING1 first, and only then to parse the ITEMs (again parsing each to completion before proceeding to the next).

Re: strtok #19043 13 Jul 11 04:40 AM
Joined: Jun 2001
Posts: 153
O
OmniLedger - Tom Reynolds Offline OP
Member
OP Offline
Member
O
Joined: Jun 2001
Posts: 153
I had already used a similar method to your workaround but just in case it was 'fixable' I thought I'd mention it.

Barry


Moderated by  Jack McGregor, Ty Griffin 

Powered by UBB.threads™ PHP Forum Software 7.7.3