Thread: tokenize method

  1. #1
    Registered User
    Join Date
    Jan 2009
    Posts
    3

    tokenize method

    This method takes two strings as input s1, a generic string, and s2 containing delimiters. s1 is verified against s2 and depending on the type of character it is stored in a two dimensional array. The problem that I have is I am not sure if the characters are stored correctly in the array, and how to arrange the delimiter characters in increasing order.


    Code:
    #pragma once
    
    class Tokenizer
    {
    public:
    	Tokenizer(void);
    	~Tokenizer(void);
    	void tokenize(char *s1, char *s2){
    			for(int i=0; i<size of s1; i++){
    			   for(int j=0; j<size of s2; j++){
    			    	if(s1[i]==s2[j]){
    				        s3[i]=s1[i];					
    				}
    				else{
    					s3[k]=s1[i];
    					k++;
    				}
    				break;					
    			   }
    		         }	
    	}
    	
    		while(i<sizeof s2){
    			l.add(s2[i]);
    		}
    	}
    
    private:
    	char * s1, * s2, * s3[][];
    	LinkedList * l=new LinkedList();
    	
    };

  2. #2
    Cat without Hat CornedBee's Avatar
    Join Date
    Apr 2003
    Posts
    8,895
    Oh dear. Please, compile the code before you post it. This is so full of compile errors, my brain tries to lock up.

    Also, use meaningful variable names.
    All the buzzt!
    CornedBee

    "There is not now, nor has there ever been, nor will there ever be, any programming language in which it is the least bit difficult to write bad code."
    - Flon's Law

  3. #3
    a newbie :p
    Join Date
    Aug 2008
    Location
    Zurich, Switzerland, Switzerland
    Posts
    91
    Take a look at this:

    Code:
    for(int i=0; i<size of s1; i++){
    	   for(int j=0; j<size of s2; j++){
    	    	if(s1[i]==s2[j]){
    see inner iteration:
    1st iteration: i = 0 and j = 0 ==> s1[0] == s2[0]?
    2nd iteration: i = 0 and j = 1 ==> s1[0] == s2[1]?
    3nd iteration: i = 0 and j = 2 ==> s1[0] == s2[2]?

    what are you trying to compare? do you think it makes sense?
    and what is "k"?

    Check this : by peter brant
    it's simple and easy to use...

    or you want something serious : check here.

  4. #4
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    937
    sizeof(x) != size of x != c++
    size of s ---> std::strlen(s)
    sizeof(ptr) = sizeof(word) != std::strlen(array_as_ptr)
    char*[][] is presumably a 2d array of strings (char pointers), rather than a 2d array of chars (char array[w][h])
    return_type function(void) is archaic; use function()
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. on method pointers and inheritance
    By BrownB in forum C++ Programming
    Replies: 2
    Last Post: 03-02-2009, 07:50 PM
  2. stuck on display method
    By shintaro in forum C++ Programming
    Replies: 2
    Last Post: 02-01-2009, 05:17 PM
  3. Best communication method to thousand childs?
    By Ironic in forum C Programming
    Replies: 8
    Last Post: 11-08-2008, 12:30 AM
  4. C# method
    By siten0308 in forum C# Programming
    Replies: 6
    Last Post: 07-15-2008, 07:01 AM
  5. Replies: 2
    Last Post: 01-22-2008, 04:22 PM