Splitting strings using strtok at another character
#1

Hello,

I want to split strings with strtok, not at a space, but on a random character, lets say ",".

Код:
new_strtok(const string[], &index){
	new length = strlen(string);
	while ((index < length) && (string[index] <= ','))
	{
		index++;
	}

	new offset = index;
	new result[20];
	while ((index < length) && (string[index] > ',') && ((index - offset) < (sizeof(result) - 1)))
	{
		result[index - offset] = string[index];
		index++;
	}
	result[index - offset] = EOS;
	return result;
}
Works perfectly fine but it still splits strings at spaces too. How can I fix that?
Reply
#2

Your using string[index] <= ','
My guess is that " " is > ","

maybe try string[index] != ','
Reply
#3

Doesnt work either...
Reply
#4

Wrote my own one.
If anyone has the same prob and needs help just reply or PM me.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)