From: Tina on
I have a function that does the following:

TCHAR *szTempFileName = ::_tcstok_s(szA, szB, &szPos);

//!< szA = D:\Rapiscan Systems\Auto Archives
\12345_20100707101212025_SERVICE2
//!< szB = D:\Rapiscan Systems\Auto Archives

However, when _tcstok_s returns, I get

//!< szTempFileName = 12345_20100707101212025_

I expect 12345_20100707101212025_SERVICE2 instead. Am I missing
something here?
From: Matti Vuori on
Tina <mstinawu(a)gmail.com> wrote in news:ea8ead85-e8ae-40f4-a9e6-
17f2a2594dfd(a)e29g2000prn.googlegroups.com:

> I have a function that does the following:
>
> TCHAR *szTempFileName = ::_tcstok_s(szA, szB, &szPos);
>
> //!< szA = D:\Rapiscan Systems\Auto Archives
> \12345_20100707101212025_SERVICE2
> //!< szB = D:\Rapiscan Systems\Auto Archives
>
> However, when _tcstok_s returns, I get
>
> //!< szTempFileName = 12345_20100707101212025_
>
> I expect 12345_20100707101212025_SERVICE2 instead. Am I missing
> something here?

I don't see any problem (which doesn't guarantee anything), so most likely
- this being a C++ program... - there is something somewhere else that
messes things up.


From: Tina on
On Jul 7, 10:42 am, Matti Vuori <xmvu...(a)kolumbus.fi> wrote:
> Tina <mstin...(a)gmail.com> wrote in news:ea8ead85-e8ae-40f4-a9e6-
> 17f2a2594...(a)e29g2000prn.googlegroups.com:
>
> > I have a function that does the following:
>
> > TCHAR *szTempFileName = ::_tcstok_s(szA, szB, &szPos);
>
> > //!< szA = D:\Rapiscan Systems\Auto Archives
> > \12345_20100707101212025_SERVICE2
> > //!< szB = D:\Rapiscan Systems\Auto Archives
>
> > However, when _tcstok_s returns, I get
>
> > //!< szTempFileName = 12345_20100707101212025_
>
> > I expect 12345_20100707101212025_SERVICE2 instead. Am I missing
> > something here?
>
> I don't see any problem (which doesn't guarantee anything), so most likely
> - this being a C++ program... - there is something somewhere else that
> messes things up.

You mean you don't see anything wrong with my assumption or with the
actual output?
From: Tina on
On Jul 7, 10:14 am, Tina <mstin...(a)gmail.com> wrote:
> I have a function that does the following:
>
> TCHAR *szTempFileName = ::_tcstok_s(szA, szB, &szPos);
>
> //!< szA = D:\Rapiscan Systems\Auto Archives
> \12345_20100707101212025_SERVICE2
> //!< szB = D:\Rapiscan Systems\Auto Archives
>
> However, when _tcstok_s returns, I get
>
> //!< szTempFileName = 12345_20100707101212025_
>
> I expect 12345_20100707101212025_SERVICE2 instead. Am I missing
> something here?

I just ended up using _wsplitpath_s instead which works for my
purposes since all I wanted was the filename.
From: Jongware on
On 07-Jul-10 22:45 PM, Tina wrote:
> On Jul 7, 10:42 am, Matti Vuori<xmvu...(a)kolumbus.fi> wrote:
>> Tina<mstin...(a)gmail.com> wrote in news:ea8ead85-e8ae-40f4-a9e6-
>> 17f2a2594...(a)e29g2000prn.googlegroups.com:
>>
>>> I have a function that does the following:
>>
>>> TCHAR *szTempFileName = ::_tcstok_s(szA, szB,&szPos);
>>
>>> //!< szA = D:\Rapiscan Systems\Auto Archives
>>> \12345_20100707101212025_SERVICE2
>>> //!< szB = D:\Rapiscan Systems\Auto Archives
>>
>>> However, when _tcstok_s returns, I get
>>
>>> //!< szTempFileName = 12345_20100707101212025_
>>
>>> I expect 12345_20100707101212025_SERVICE2 instead. Am I missing
>>> something here?
>>
>> I don't see any problem (which doesn't guarantee anything), so most likely
>> - this being a C++ program... - there is something somewhere else that
>> messes things up.
>
> You mean you don't see anything wrong with my assumption or with the
> actual output?

strtok, and all of its derived MSC cousins, does not work by finding 'a
string within another string'. The first argument is the input string --
the one to parse.
The second one, however, is *not* a literal string. It's just a long
list of tokens that are valid separator characters. The separators
themselves are discarded, and the first call to strtok (or its
derivatives) returns the first set of input that consist of
non-consecutive runs of the separators. Next calls to strtok will skip
all separators, then return the *next* run of characters, etc.

Your first call returns a run of digits and underscores, which is
correct, because neither of these are in your separator "list". The
character 'S', however, *is*, so the input string gets cut off there.
Another call to strtok will return the single character string "E", and
if you can tell why, you got the idea.

You might simply be using the wrong function for what you are trying to
achieve.

[Jw]