Re: strtok causes Segmentation fault
- From: "void * clvrmnky()" <clvrmnky.invalid@xxxxxxxxxxxxxxxxxxx>
- Date: Fri, 12 May 2006 11:18:07 -0400
bofh1234@xxxxxxxxxxx wrote:
Think:So?? I tried strtok(*list, ";"); and it still seg faults. AccordingI understand strtok seg faulting if the FIRST call is with NULL, butYou are passing a string literal as the list parameter, which you then
in my case the first call is not NULL. It is
tokenptr = strtok(list, ";"); //this line causes the seg fault WHY?
list is a varible passed to the function.
send to strtok(). This causes undefined behavior.
to my old C book strtok is supposed to take a string for the first
argument. I even tried changing createvarible to:
int createvarible(const int sock, char *varname, char *vartype, char
*initialvalue, char accesslist[64])
and I still get a seg fault. How can I get this thing to work.
char *strtok(char *s1, const char *s2);
The string [s1] passed to strtok() must be mutable, because it is a destructive function. Your appear to be passing the function a static buffer or literal string.
Slow down a bit and re-read all the comments posted so far.
Consider:
[...]
char *fnord = "Fnord Motor Company";
fnord[0] = 'f'; /* Undefined behaviour */
[...]
Can you legally modify fnord, even with a direct assignment? If not, what about a library function like strtok()?
.
- References:
- strtok causes Segmentation fault
- From: bofh1234
- Re: strtok causes Segmentation fault
- From: void * clvrmnky()
- Re: strtok causes Segmentation fault
- From: Joe Smith
- Re: strtok causes Segmentation fault
- From: void * clvrmnky()
- Re: strtok causes Segmentation fault
- From: bofh1234
- Re: strtok causes Segmentation fault
- From: Default User
- Re: strtok causes Segmentation fault
- From: bofh1234
- strtok causes Segmentation fault
- Prev by Date: Re: Listing the most dangerous parts of C
- Next by Date: <OT> Re: continue with switch
- Previous by thread: Re: strtok causes Segmentation fault
- Next by thread: Re: strtok causes Segmentation fault
- Index(es):
Relevant Pages
|