Thread: strtok

  1. #1


    can someone please explane how i would tokenize a string looking for words that begin with an underscore or a capital or lowercase letter. I think i would use strtok but im not sure of the syntax. I also want to find words that end with : the problem is that some of the words that end with : are also words that begin with an underscore or a capital or lowercase letterbut i need to keep them seprate.

  2. #2
    Registered User
    Join Date
    Sep 2001
    The one great thing about syntax is that you can look it up whenever you need to.

    Now, about those words.....

    You have words that sometimes begin with an underscore, a capital, or a lowercase letter.....

    Some examples I assume would look like this:


    And you're asking how to eliminate those words, but keep words in the string that end in a colon (

    So to get this string: aardvark _underscore Pentium keepme:

    to look like this: keepme:

    Is this correct?

  3. #3
    no i want to take all of the words (strings sepparated by whitespace) that end with : and put them into a field of a node on a linked list and all of the words that begin with underscore or cap or lowercase and put them into another field of a node in a linked list each node in the list will contain 4 fields

  4. #4
    Here's a very very very simple way to do this:
    char word[1024]={0};
    int x=0;
    FILE* fp = fopen("DoYourOwnErrorChecking.Ok", "r" );
       word[x] = fgetc( fp );
       if ( isspace( word[x] ) ) {
          catagorize( word ); // drop this word in the correct node
          x = 0;
       else x++;
    while( !feof( fp ) );
    Now, you make a function that is passed a single word:
    void catagorize( char *word )
       int startsWithUnderline = 0;
       int endsInColon = 0;
       int startsWithLower = 0;
       if( word == NULL ) return;
       if( word[0] == '_' ) startsWithUnderline = 1;
       else if ( isupper( word[0] ) ) startsWithLower = 1;
       if( startsWithUnderline && endsInColon )
          addToNode( underlineColonNode, word );
       if( ...
    You get the idea.


Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 20q game problems
    By Nexus-ZERO in forum C Programming
    Replies: 24
    Last Post: 12-17-2008, 05:48 PM
  2. strtok is causing segmentation fault
    By yougene in forum C Programming
    Replies: 11
    Last Post: 03-08-2008, 10:32 AM
  3. trying to use strtok() function to parse CL
    By ohaqqi in forum C Programming
    Replies: 15
    Last Post: 07-01-2007, 09:38 PM
  4. Help debugging my program
    By shoobsie in forum C Programming
    Replies: 4
    Last Post: 07-05-2005, 07:14 AM
  5. Trouble with strtok()
    By BianConiglio in forum C Programming
    Replies: 2
    Last Post: 05-08-2004, 06:56 PM