Click to See Complete Forum and Search --> : strtok in C, need help with syntax?


digitalzero
03-18-2002, 10:15 AM
say i have variables: line, token
where line: line with delim
token: token of line
all of type char *

now then i have type char variable named del
char del;
del = ',';

how do i use the strtok?

this is what i've tried:

token = strtok(line,&delim);

it compiles alrite, but when i run something like: "hello,hello"
ERROR: Segmentation Fault

Is it my syntax thats wrong? Someone help!

[ 18 March 2002: Message edited by: digitalzero ]

MrNewbie
03-18-2002, 11:01 AM
There's a strtok example here:
http://www.codeexamples.org/cgi-bin/c2h/hl.cgi?filename=strtok.c&type=HTML-detail

I'm not totally sure what you mean in what you said but maybe that link will help.

Stuka
03-18-2002, 11:17 AM
Rather than:char del; try using:char* del = ",";. strtok() expects a null terminated string for the delimiter(s). It's probably overrunning the end of your char, and hitting something beyond it, causing the segfault.