Sponsored Content
Top Forums Programming How to use strtok twice in the same program? Post 302244102 by Saurabh78 on Tuesday 7th of October 2008 07:56:00 AM
Old 10-07-2008
better use strtok_r
 

10 More Discussions You Might Find Interesting

1. Programming

better way than strtok?

Hi all, Right now I'm using this but it seems to be a hack: if (prefix(arg, "mark=")) { for (markid = strtok(args,"="); markid; markid=strtok((char *)NULL, "=")) { basically the user passes "mark=ny" to the command. I want to be able to extract "ny" from that... (7 Replies)
Discussion started by: annie
7 Replies

2. Linux

Strtok function....

can any help me out y dis program is giving me a segmentation fault..... #include<stdio.h> #include<string.h> int main() { char *str="Tanvir/home/root/hello"; const char *d ="/"; char *ret; ret=strtok(str,d); if(ret==NULL) printf("NULL NULL"); else ... (3 Replies)
Discussion started by: Tanvirk
3 Replies

3. Programming

Regardign strtok() output directing to 2-D string array

Hi, I just wrote a program in C to split a comma seperated string in to group of strings using strtok() function. The code is: int main() { char *temp;//not used here but basically we extract one string after another using strtok() and assign to a string pointer defined like this. ... (3 Replies)
Discussion started by: SankarV
3 Replies

4. Shell Programming and Scripting

strtok equivalent in perl

Hi All, Is their any equivalent for strtok (in c) to use in perl script. Thanks in advance. JS (1 Reply)
Discussion started by: jisha
1 Replies

5. UNIX for Dummies Questions & Answers

Script to open program and send/execute command in program

Hi, i want to write a script that executes a program (exec?) . this program then requires a filename as input. how do i give it this input in the script so the program will be complete run and close by the script. e.g. exec prog.exe program then asks for filename "enter filename:"... (1 Reply)
Discussion started by: tuathan
1 Replies

6. Programming

strtok with while loops

Why is line (null) after the first while loop run? (keyword does jump to the next word.) #include <ftw.h> #include <stdio.h> #include <string.h> char filenames = ""; int list(const char *name, const struct stat *status, int type) { if( (type == FTW_F) && strstr(name, ".txt") &&... (3 Replies)
Discussion started by: cyler
3 Replies

7. Programming

Python program faster than C++ program.

I wrote a simple program that generates a random word 10,000,000 times. I wrote it in python, then in C++ and compared the two completion times. The python script was faster! Is that normal? Why would the python script be faster? I was under the impression that C++ was faster. What are some of... (2 Replies)
Discussion started by: cbreiny
2 Replies

8. Homework & Coursework Questions

Calling compiled C program with Perl program

Long story short: I'm working inside of a Unix SSH under a bash shell. I have to code a C program that generates a random number. Then I have to call the compiled C program with a Perl program to run the C program 20 times and put all the generated random #s into a text file, then print that text... (1 Reply)
Discussion started by: jdkirby
1 Replies

9. Programming

strtok() gives segmentation fault!!

#include<iostream.h> #include<string> #include<stdio.h> int main() { char *cmd="delete backup backup-iso image a.iso b.iso c.iso d.iso"; char *tokenized_cmd,*sub_cmd; sub_cmd=strstr(cmd,"image"); tokenized_cmd=strtok(sub_cmd," "); ... (3 Replies)
Discussion started by: ashwini.engr07
3 Replies

10. Shell Programming and Scripting

Perl program get a response before the program quits

I created a program, so a kid can practice there math on it. It dispenses varies math problems and the kid must input an answer. I also want it to grade the work they have done, but I can't find the best place for it to print out the grade. I have: if ( $response =~ m/^/ ) { $user_wants_to_quit... (1 Reply)
Discussion started by: germany1517
1 Replies
STRTOK(3)						     Linux Programmer's Manual							 STRTOK(3)

NAME
strtok, strtok_r - extract tokens from strings SYNOPSIS
#include <string.h> char *strtok(char *s, const char *delim); char *strtok_r(char *s, const char *delim, char **ptrptr); DESCRIPTION
A `token' is a nonempty string of characters not occurring in the string delim, followed by or by a character occurring in delim. The strtok() function can be used to parse the string s into tokens. The first call to strtok() should have s as its first argument. Subse- quent calls should have the first argument set to NULL. Each call returns a pointer to the next token, or NULL when no more tokens are found. If a token ends with a delimiter, this delimiting character is overwritten with a and a pointer to the next character is saved for the next call to strtok(). The delimiter string delim may be different for each call. The strtok_r() function is a reentrant version of the strtok() function, which instead of using its own static buffer, requires a pointer to a user allocated char*. This pointer, the ptrptr parameter, must be the same while parsing the same string. BUGS
Never use these functions. If you do, note that: These functions modify their first argument. These functions cannot be used on constant strings. The identity of the delimiting character is lost. The strtok() function uses a static buffer while parsing, so it's not thread safe. Use strtok_r() if this matters to you. RETURN VALUE
The strtok() function returns a pointer to the next token, or NULL if there are no more tokens. CONFORMING TO
strtok() SVID 3, POSIX, BSD 4.3, ISO 9899 strtok_r() POSIX.1c SEE ALSO
index(3), memchr(3), rindex(3), strchr(3), strpbrk(3), strsep(3), strspn(3), strstr(3) GNU
2000-02-13 STRTOK(3)
All times are GMT -4. The time now is 04:27 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy