Alternative to STRTOK In tokenizing 
Author Message
 Alternative to STRTOK In tokenizing

Hello,

   I am trying to find a better way to chop up a line than using
strtok.  Strtok skips over blanks and my list always ends up
incomplete.  Are there any built in C functions that act on a line where
you can perhaps pull delimited information out?  Thanks

[not built-in, but you might look at the 4.4BSD "strsep()". -mod]

Ralf
--



Sun, 12 Jan 2003 03:00:00 GMT  
 Alternative to STRTOK In tokenizing

Quote:
> Hello,

>    I am trying to find a better way to chop up a line than using
> strtok.  Strtok skips over blanks and my list always ends up
> incomplete.  Are there any built in C functions that act on a line where
> you can perhaps pull delimited information out?  Thanks

> [not built-in, but you might look at the 4.4BSD "strsep()". -mod]

There's the regular expression support in libc.  The regex routines
and data types are a bit awkward to work with, but you can write
wrapper functions that suit your needs.  

I have a couple of such wrappers around if you'd like to see them
... just email me directly.

[well, they aren't part of standard libc, but it's an interesting suggestion.
 -mod]

--
--Ed Cashin                     PGP public key:

    Note: If you want me to send you email, don't munge your address.
--



Sun, 12 Jan 2003 03:00:00 GMT  
 Alternative to STRTOK In tokenizing

Quote:
>   I am trying to find a better way to chop up a line than using
>strtok.  Strtok skips over blanks and my list always ends up
>incomplete.  Are there any built in C functions that act on a line where
>you can perhaps pull delimited information out?  Thanks

For simple things, I often use sscanf()'s charcacter classes followed
by an offset, e.g.:
        ok = sscanf(str, "%[^,;]%n", item, &offset);
        str += offset+1;
gets an item from the string consisting of everything from the current
position until the next comma or semicolon, and positions the string
pointer just after that.  To skip over things, character classes with
'*' modifier (i.e. "%*[...]") are also quite useful.

Regards,
Ingo
--
PGP&GnuPG keys: http://www.informatik.uni-oldenburg.de/~ingo/{pgp|gpg}key.asc
"The irony is that Bill Gates claims to be making a stable operating system and
 Linus Torvalds claims to be trying to take over the world." -- somebody on /.
--



Thu, 16 Jan 2003 03:00:00 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. Alternative to STRTOK In tokenizing

2. Alternative to strtok?

3. strtok alternative?

4. Tokenizing a comma delimited string with quotes around each token

5. tokenize string

6. how to tokenize the string in c??

7. help with tokenize

8. Tokenizing dynamically allocated memory

9. How to tokenize without corrupting source string?!

10. tokenizing

11. Tokenize

12. Q: tokenizing

 

 
Powered by phpBB® Forum Software