About Chandra Archive Proposer Instruments & Calibration Newsletters Data Analysis HelpDesk Calibration Database NASA Archives & Centers Chandra Science Links

Skip the navigation links
Last modified: December 2006

URL: http://cxc.harvard.edu/ciao3.4/strtok.tm.html
Hardcopy (PDF): A4 | Letter
AHELP for CIAO 3.4 strtok Context: slangrtl

Synopsis

Extract tokens from a string

Syntax

String_Type[] strtok (String_Type str [,String_Type white])

Description

strtok breaks the string str into a series of tokens and returns them as an array of strings. If the second parameter white is present, then it specifies the set of characters that are to be regarded as whitespace when extracting the tokens, and may consist of the whitespace characters or a range of such characters. If the first character of white is '^', then the whitespace characters consist of all characters except those in white. For example, if white is " \t\n,;.", then those characters specifiy the whitespace characters. However, if white is given by "^a-zA-Z0-9_", then any character is a whitespace character except those in the ranges a-z, A-Z, 0-9, and the underscore character.

If the second parameter is not present, then it defaults to " \t\r\n\f".

Example

The following example may be used to count the words in a text file:

    define count_words (file)
    {
       variable fp, line, count;

       fp = fopen (file, "r");
       if (fp == NULL) return -1;

       count = 0;
       while (-1 != fgets (&line, fp))
         {
           line = strtok (line, "^a-zA-Z");
           count += length (line);
         }
       () = fclose (fp);
       return count;
    }
Hardcopy (PDF): A4 | Letter
Last modified: December 2006



The Chandra X-Ray Center (CXC) is operated for NASA by the Smithsonian Astrophysical Observatory.
60 Garden Street, Cambridge, MA 02138 USA.    Email: cxcweb@head.cfa.harvard.edu
Smithsonian Institution, Copyright © 1998-2004. All rights reserved.