Re: segmentation fault in strtok_r()
From: Artie Gold (artiegold_at_austin.rr.com)
Date: 07/30/03
- Next message: Marc Rochkind: "Re: Programming the human mind using scrypnosis"
- Previous message: David Schwartz: "Re: persistent malloc"
- In reply to: Paul Pluzhnikov: "Re: segmentation fault in strtok_r()"
- Next in thread: Paul Pluzhnikov: "Re: segmentation fault in strtok_r()"
- Reply: Paul Pluzhnikov: "Re: segmentation fault in strtok_r()"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Wed, 30 Jul 2003 03:44:17 GMT
Paul Pluzhnikov wrote:
> Artie Gold <artiegold@austin.rr.com> writes:
>
>
>>> pTOK = strtok_r( pCharArray , " " , &pPTR );
>>> printf("pCharArray=%s", pCharArray ) ;
>>> while( pTOK != NULL ){
>>> index++;
>>> len = len + strlen(pTOK) ;
>>> pTOK = strtok_r( NULL , " " , &pPTR );
>>
>>strtok_r requires a pointer to space that _exists_.
>>Please see the man page.
>
>
> Huh? I think *you* need to revisit the man page ;-)
OK, I just did....
>
> The strtok_r() function works the same as the strtok()
> function, but instead of using a static buffer it uses a
> pointer to a user allocated char* pointer. This pointer,
> the ptrptr parameter, must be the same while parsing the
> same string.
Have I gone brain-dead? :-(
>
> His use of strtok_r() is correct, but
>
>
>>>int main()
>>>{
>>> printf("%s", trimLeadEndSpace( ":myAppAddress@hotmail.com ;
>>
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> this is a problem: quoted string literals are not writable (and
> strtok_r() *does* write to its argument).
All right. I heard hoofbeats, and though "zebras" instead of
horses...but I couldhave sworn there was at leat _one_ zebra in there! ;-)
>
> In fact, CC warned him about it:
>
> "junk.cc", line 65: Warning: String literal converted to char*
> in formal argument pCharArray in call to trimLeadEndSpace(char*).
>
Cheers,
--ag
-- Artie Gold -- Austin, Texas
- Next message: Marc Rochkind: "Re: Programming the human mind using scrypnosis"
- Previous message: David Schwartz: "Re: persistent malloc"
- In reply to: Paul Pluzhnikov: "Re: segmentation fault in strtok_r()"
- Next in thread: Paul Pluzhnikov: "Re: segmentation fault in strtok_r()"
- Reply: Paul Pluzhnikov: "Re: segmentation fault in strtok_r()"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]