#include #include #include #include #include const char string[] = "COM1 COM2 LPT1 LPT2 USB0"; const char delimiters[] = " ,-:"; char *my_array; char *running; char *token; char *passed_string; char *string2; int l; int conv_str_to_array(char *passed_string); int main() { running = strdup(string); int j = 0; while (j != 1) { token = strsep (&running, delimiters); if (token != NULL) { printf("token %s\n", token); } else { j = 1; } } /* trying to use our new function */ string2 = strdup(string); l = conv_str_to_array(string2); printf("%d\n", l); return 0; } /* trying to make it to a function wich is passed a string as argument */ int conv_str_to_array(char *passed_string) { running = strdup(passed_string); int j,k = 0; while (j != 1) { token = strsep (&running, delimiters); if (token != NULL) { my_array[k] = *token; k++; } else { j = 1; } } return k; }