strtok

This is a discussion on strtok within the C Programming forums, part of the General Programming Boards category; can someone please explane how i would tokenize a string looking for words that begin with an underscore or a ...

  1. #1
    Unregistered
    Guest

    strtok

    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
    Posts
    8
    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:

    aardvark
    _underscore
    Pentium

    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
    Unregistered
    Guest
    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
    Unregistered
    Guest
    Here's a very very very simple way to do this:
    Code:
    char word[1024]={0};
    int x=0;
    FILE* fp = fopen("DoYourOwnErrorChecking.Ok", "r" );
    
    do
    {
       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:
    Code:
    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.

    Quzah.

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, 04:48 PM
  2. strtok is causing segmentation fault
    By yougene in forum C Programming
    Replies: 11
    Last Post: 03-08-2008, 09: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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21