So I'm trying to remove 2 brackets from lines I'm reading from a file.
For some reason when I run my program the characters in between the delimeters is removed.

for example
greetings pe()ple
would end up as
greetings pe

I'm using a char array of delimiters.
char delimiters[] = " ( )";

Why does strtok delete the characters between the parenthesis?

Edited by pritaeas: Moved to Sofware Dev.

2 Years
Discussion Span
Last Post by Pyler

Is this PHP? The function should be seperating the string into tokens based on the delimiter. In your example 'greeting pe' would become the first token of the tokenised string. The example from the PHP man page may help.

$string = "This is\tan example\nstring";
/* Use tab and newline as tokenizing characters as well  */
$tok = strtok($string, " \n\t");

while ($tok !== false) {
    echo "Word=$tok<br />";
    $tok = strtok(" \n\t");

As you can see, $tok is used repeatedly to move through the string. SO if you did a loop like the one above further calls to strtok should move through your string.


Misunderstanding of how strtok works.
Have to seperate token into different fields.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.