Sponsored Content
Top Forums Programming Is this string splitting function OK? Post 302236178 by Saurabh78 on Monday 15th of September 2008 02:58:11 AM
Old 09-15-2008
I have not go through the entire code.
But if you have multiple threads, then possibly strtok function is not thread safe.
Use strtok_r() .
 

10 More Discussions You Might Find Interesting

1. UNIX for Dummies Questions & Answers

splitting a string in unix

i need to split a line using a delimiter, and store it into a array :( (2 Replies)
Discussion started by: lmadhuri
2 Replies

2. Shell Programming and Scripting

string splitting

Hi, I have a string like 'xyz' and i want to to split the above string into letters for comparision purpose. any idea pls. cheers RRK. (3 Replies)
Discussion started by: ravi raj kumar
3 Replies

3. Shell Programming and Scripting

Splitting a string

Hi, I am new to shell scripting, Can any body suggest me how I can split a string with a delimiter as whitespace into words and store into a array. I have read a line from file, now I want to split the line into words and store in a array for further use. eg : the sky is blue want... (3 Replies)
Discussion started by: smk
3 Replies

4. Shell Programming and Scripting

Splitting a string with awk

Hi all, I want to split a string in awk and treat each component seperatley. I know i can use: split ("hi all", a, " ") to put each delimited component into array a. However when i want to do this with just a string of chars it does not work split ("hi", a, ""); print a; prints... (6 Replies)
Discussion started by: pxy2d1
6 Replies

5. Shell Programming and Scripting

Perl - Need help on splitting string

Let's say I have a very long string with no spaces but just words stored in $very_long_string. $very_long_string = "aaaaaaaaaaabbbbbbbbbbbccccccccccccdddddddddddd"; I can do this to split the string into 1 character each and store them in an array: @myArray = split(//, $very_long_string); ... (3 Replies)
Discussion started by: teiji
3 Replies

6. UNIX for Dummies Questions & Answers

Splitting a string and putting another string in the middle?

Hello all! I'm trying to put together a small script that will take in a file name and attach a datestamp to the end of it (but before the file type extension). To illustrate... Before: filename.txt anotherfilename.txt After: filename_20090724.txt anotherfilename_20090724.txt ... (7 Replies)
Discussion started by: jisoo411
7 Replies

7. Shell Programming and Scripting

splitting words from a string

Hi, I have a string like this in a file, I want to retrive the words separated by comma's in 3 variables. like How do i get that.plz advice (2 Replies)
Discussion started by: suresh_kb211
2 Replies

8. UNIX for Dummies Questions & Answers

Help with splitting a string..

Hello I need help with the following. I have strings like #if defined(__def1__) #if defined(__def1__) || defined(__def2__) #if defined(__def1__) && defined(__def2__) && defined(__def3__). #if defined(__def1__) || defined(__def2__) || defined(__def3__). I need to print what is there in... (4 Replies)
Discussion started by: srk
4 Replies

9. Shell Programming and Scripting

Splitting string with awk

Input: Debris Linux is a minimalist, desktop-oriented distribution and live CD based on Ubuntu. It includes the GNOME desktop and a small set of popular desktop applications, such as GNOME Office, Firefox web browser, Pidgin instant messenger, and ufw firewall manager. Debris Linux ships... (5 Replies)
Discussion started by: cola
5 Replies

10. Shell Programming and Scripting

Splitting delimited string into rows

Hi, I have a requirement that has 50-60 million records that we need to split a delimited string (Delimeter is newline) into rows. Source Date: SerialID UnidID GENRE 100 A11 AAAchar(10)BBB 200 B11 CCCchar(10)DDD(10)ZZZZ Field 'GENRE' is a string with new line as delimeter and not sure... (5 Replies)
Discussion started by: techmoris
5 Replies
STRTOK(3)						   BSD Library Functions Manual 						 STRTOK(3)

NAME
strtok, strtok_r -- string tokens LIBRARY
Standard C Library (libc, -lc) SYNOPSIS
#include <string.h> char * strtok(char * restrict str, const char * restrict sep); char * strtok_r(char *str, const char *sep, char **lasts); DESCRIPTION
The strtok() function is used to isolate sequential tokens in a nul-terminated string, str. These tokens are separated in the string by at least one of the characters in sep. The first time that strtok() is called, str should be specified; subsequent calls, wishing to obtain further tokens from the same string, should pass a null pointer instead. The separator string, sep, must be supplied each time, and may change between calls. The strtok() function returns a pointer to the beginning of each subsequent token in the string, after replacing the separator character itself with a NUL character. Separator characters at the beginning of the string or at the continuation point are skipped so that zero length tokens are not returned. When no more tokens remain, a null pointer is returned. The strtok_r() function implements the functionality of strtok() but is passed an additional argument, lasts, which points to a user-provided pointer which is used by strtok_r() to store state which needs to be kept between calls to scan the same string; unlike strtok(), it is not necessary to limit tokenizing to a single string at a time when using strtok_r(). EXAMPLES
The following will construct an array of pointers to each individual word in the string s: #define MAXTOKENS 128 char s[512], *p, *tokens[MAXTOKENS]; char *last; int i = 0; snprintf(s, sizeof(s), "cat dog horse cow"); for ((p = strtok_r(s, " ", &last)); p; (p = strtok_r(NULL, " ", &last)), i++) { if (i < MAXTOKENS - 1) tokens[i] = p; } tokens[i] = NULL; That is, tokens[0] will point to "cat", tokens[1] will point to "dog", tokens[2] will point to "horse", and tokens[3] will point to "cow". SEE ALSO
index(3), memchr(3), rindex(3), strchr(3), strcspn(3), strpbrk(3), strrchr(3), strsep(3), strspn(3), strstr(3) STANDARDS
The strtok() function conforms to ANSI X3.159-1989 (``ANSI C89''). The strtok_r() function conforms to IEEE Std 1003.1c-1995 (``POSIX.1''). BUGS
The System V strtok(), if handed a string containing only delimiter characters, will not alter the next starting point, so that a call to strtok() with a different (or empty) delimiter string may return a non-NULL value. Since this implementation always alters the next starting point, such a sequence of calls would always return NULL. BSD
August 11, 2002 BSD
All times are GMT -4. The time now is 09:00 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy