I have created function that splits the char*
into vector
but the problem is that after running this method all elements of this vector
are the last element in the input line.
Example:
input:abc def ghi
vector: ghi, ghi, ghi
vector <const char*> dane;
void split(char* str, char* sep){
char* cstr = str;//str.c_str konwersja str na char*
char* current;
current = strtok(cstr, sep);
string s;
while(current != NULL){
s = current;
int foundF = s.find_first_not_of("-.\"-\\/!,`");
int foundL = s.find_last_not_of("-.\"-\\/!,`");
if(foundL==string::npos)//find first or last zwrocilo nulla
foundL = s.length();
if(foundF==string::npos)
foundF = 0;
s = s.substr(foundF, foundL + 1);
const char* c = s.c_str();
dane.push_back(c);
current=strtok(NULL, sep);
}
}
int main(){
char* c = new char[256];
cin.getline(c,256);
cout<<c<<endl;
split(c, " ");
for(int i = 0; i < dane.size(); i++){
cout<<dane.at(i)<<endl;
}
return 0;
}