[EDITED] i want to write a function to split given string in reverse order and store it in string array , something like:
string* splitStr(string s, char c,int& ssize) {
int size = s.size();
string* ss = new string[size];
int count = 0;
ssize = 0;
for (int j = 0; j < size; j++) {
if (s.at(j) == c) {
count++;
}
}
ssize = ++count;
for (int i = 0; i<size; i++) {
if (s.at(i) == c) { ssize--; continue; }
else { ss[ssize] += s.at(i); }
}
ssize = count;
return ss;
}
Sample program:
string s = "this is some damn";
int size = 0;
string* ss = splitStr(s, ' ', size);
for (int i = 0; i < size; i++) {
cout << ss[i] << "\n";
}
system("PAUSE");
Output:
(this is empty line)
damn
some
is
it's just a rough attempt , but generally it's very unreliable approach don't you think ? what could be the best possible solution is this case , without using any other data type except string,char,int,float ?