C and C++

Moderators: None (Apply to moderate this forum)
Number of threads: 28629
Number of posts: 94611

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
tokenize method Posted by e4321 on 23 Jan 2009 at 5:54 AM
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();

};
Report
Re: tokenize method Posted by Lundin on 23 Jan 2009 at 7:42 AM
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.
Report
Re: tokenize method Posted by e4321 on 24 Jan 2009 at 6:59 AM
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.





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.