Surely split should return and array of char*[], where each pointer points to the string after it has been split, in your example where you are splitting by the delimiter ',', the return would be:
char* pResults[] = split( "-7,10,4", ',' );
pResults[0] would point to -7
pResults[1] would point to 10
pResults[2] would point to 4
Thats how split normally works, explode in php works the same way.
Not surprised that it doesn't work. You need to read up on strtok(). It isn't a String function. It works on C type strings, meaning NULL-terminated char arrays.
Here is my java code for split....the only reason I wrote this was because the JVM I'm using on a particular platform is old and doesn't have the split routine:
public static String[] splitBuffer( char[] aryBuffer, String strDelimiter ) {
try{
if ( aryBuffer == null || aryBuffer.length == 0) {
throw new Exception( "Invalid buffer!" );
}
if ( strDelimiter == null || strDelimiter.length() == 0 ) {
throw new Exception( "Invalid delimiter!" );
}
// Count the instances of the delimiter
String[] aryRecords = null;
for( int p=0; p<2; p++ ) {
int intLines = 0;
for( int b=0; b<aryBuffer.length; b++ ) {
// Look for the delimiter which could be multiple bytes
int d, t=b;
for( d=0; d<strDelimiter.length(); d++, t++ ) {
if ( aryBuffer[t] != strDelimiter.charAt(d) ) {
break;
}
}
if ( p == 1 && d != strDelimiter.length() ) {
if ( aryRecords[intLines] == null ) {
aryRecords[intLines] = "";
}
aryRecords[intLines] += aryBuffer[b];
} else if ( d == strDelimiter.length() ) {
// Re-initialise the start reference byte, skipping over the delimiter
b += strDelimiter.length();
// Subtract 1 as the loop with add 1
b--;
// Increment the total number of lines
intLines++;
}
}
if ( p == 0 && intLines > 0 ) {
// Create the string array
aryRecords = new String[ (intLines + 1) ];
}
}
return aryRecords;
} catch( Exception ex ) {
// Report exception here...
}
return null;
}