Hi,
If any of you know JavaScript, you will know about the split() member function of a string. In it's simplest form, it splits the string that you call it from by the char argument and returns an array. I found this very useful, so I tried to write it in C++. Here is the code:
char **split(char *split_string,char splitby) {
int i,j,l,sslen=strlen(split_string);
/*
'k' is a global variable that I can access to tell me how long was the array returned when the string was processed.
An example of this functions use might be
char **splitup=split(mystring,' ');
*/
char str_arr[sslen/2][sslen];
for(i=0; i<sslen; i++) {
if(split_string[i]==splitby) {
k++;
for(j=i-1,l=0; j>0; j--,l++) {
if(split_string[j]==splitby) break;
str_arr[k][l]=split_string[j];
}
}
}
if(k=0) strcpy(str_arr[0],split_string);
return str_arr;
}
Why does my compiler (Turbo c++ v 3) return errors?