-
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();
};
-
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.
-
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.
-
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()