hi im trying to split up a string e.g: execute -b / run -r / shout -s into 2 different strings.
*First array of strings will contain the following, with "/" taken out:
1st string: buffer[0]=execute -b
2nd string: buffer[1]=run -r
3rd string: buffer[2]=shout -a
*Second array of strings will contain a further tokenized string of each word before any flags:
1st string: buffer2[0]=execute
2nd string: buffer2[1]=run
3rd string: buffer2[2]=shout
i came out with this rough idea but im still uncertain at some parts and i hope someone would show me where there might be problems.
Is there a more efficient or shorter way to produce the same result ?Code:char* temp; char** buffer; /* i do not have a definite size to malloc this, wat should specify for the char** buffer2; * size for malloc? */ int i; i=0; temp = strtok(somevalue, "/"); while (temp) { buffer[i] = temp; strtok(NULL, "/"); i++; } /* loop through buffer */ for( i = 0; i < sizeof(buffer); i++) { /* can i actually loop all the contents of the string array temp = strtok(buffer[i], " "); * like that? */ buffer2[i] = temp; }



LinkBack URL
About LinkBacks



