Home
 
 
Search:  
C C++ Perl PHP Python HTML ShellScripts
 
 
  Coding Books
  Tutorials
  Search Code
  Browse Code
  Link to Us
  Site News
  Contact Metalshell
 
 
 
  Submit Code   Statistics
 



Embedded Systems Building Blocks: Complete and Ready-To-Use Modules in C    (ISBN: 0879306041)


 

 List Price: $89.95
 Our Price: $62.97
 Used Price: $39.00

 Release Date: February, 2000
 Manufacturer: CMP Books (Hardcover)
 Sales Rank: 14,998

 Author: Jean J. Labrosse









More Info

 String Tokenizer 2002-02-23 16:04:39
 
Category: source:c:strings
Description: Example on how to use strtok() to break apart a string.
Platform: unix/win
Author: mind
Viewed: 37094
Rating: 4.2/5 (244 votes)
If you have any questions about this piece of code or still need help, try posting your question on the forum.

 

Printable Version
strtok.c
/* strtok example by mind@metalshell.com
 *
 * This is an example on string tokenizing
 *
 * 02/19/2002
 *
 * http://www.metalshell.com
 *
 */

#include <stdio.h>
#include <string.h>

int main(int argc, char *argv[])
{
        int x = 1;
        char str[]="this:is:a:test:of:string:tokenizing";
        char *str1;

        /* print what we have so far */
        printf("String: %s\n", str);

        /* extract first string from string sequence */
        str1 = strtok(str, ":");

        /* print first string after tokenized */
        printf("%i: %s\n", x, str1);

        /* loop until finishied */
        while (1)
        {
                /* extract string from string sequence */
                str1 = strtok(NULL, ":");

                /* check if there is nothing else to extract */
                if (str1 == NULL)
                {
                        printf("Tokenizing complete\n");
                        exit(0);
                }

                /* print string after tokenized */
                printf("%i: %s\n", x, str1);
                x++;
        }

        return 0;

}
Rate this code:
(Not Helpful)  (Very Helpful) 

 
 
   Developer.*  
   Blue Parrots  
   Technipal  
   Defy Magazine  
   Code Project  
   Prog. Heaven  


Got Money?