Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Sign In with Facebook Sign In with Google Sign In with OpenID

Categories

We have migrated to a new platform! Please note that you will need to reset your password to log in (your credentials are still in-tact though). Please contact lee@programmersheaven.com if you have questions.
Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

tokenize method

e4321e4321 Posts: 6Member
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.

#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();

};

Comments

  • LundinLundin Posts: 3,711Member
    I don't quite understand what you want. The algorithm itself doesn't make any sense. And where are the strings allocated?

    char * s1, * s2, * s3[][];

    Why did you make two one-dimensional pointers and one three-dimensional?


    : LinkedList * l=new LinkedList();

    This isn't valid C++, all initialization must be done in the constructor.


    : while(i<sizeof s2){

    This won't work, s2 is a pointer and not a statically allocated array.
  • e4321e4321 Posts: 6Member
    I was trying to separate between delimiters and string literals (sin, cos, tan) and store them in one string, but I am not sure if this is the exact requirement.


Sign In or Register to comment.