LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-30-2004, 11:38 PM   #1
irfanhab
Member
 
Registered: Jan 2004
Location: Pakistan
Distribution: OpenSuse 10.2, Slackware 11, Solaris 10
Posts: 415

Rep: Reputation: 34
strsep vs. strtok


Hi all,

I need to tokenize my string in a program, but using strtok, the original string is changed.
I read that strsep, leaves the original string unaltered.
Can anyone give me a sample code using strsep?
thanx
 
Old 05-01-2004, 01:08 AM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
Code:
       char *strsep(char **stringp, const char *delim);

DESCRIPTION
       If  *stringp  is  NULL, the strsep() function returns NULL
       and does nothing else. Otherwise, this function finds  the
       first  token  in  the  string  *stringp,  where tokens are
       delimited by symbols in the string delim.  This  token  is
       terminated  with  a  `\0'  character  (by  overwriting the
       delimiter) and *stringp  is  updated  to  point  past  the
       token.  In case no delimiter was found, the token is taken
       to be the entire string *stringp,  and  *stringp  is  made
       NULL.

NOTES
       The strsep() function was introduced as a replacement  for
       strtok(),  since  the  latter  cannot handle empty fields.
       However, strtok() conforms to ANSI-C  and  hence  is  more
       portable.
I think you were misinformed...I made the most relevant information bold.

It's probably best to just duplicate the original string to use with strtok(). By using the strdup() function for instance.

Last edited by itsme86; 05-01-2004 at 01:10 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
C using strtok to parse by quotes? zero79 Programming 3 03-07-2005 03:44 PM
how to print the first character in a string using strtok its_godzilla Programming 5 02-02-2005 10:22 AM
strtok pantera Programming 2 12-19-2004 01:04 PM
free memory from strtok? swinchen Programming 1 09-08-2004 11:01 PM
Alternatives to strtok? jpbarto Programming 4 03-26-2004 01:20 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 11:32 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration