I have used to split C strings by many means: strstr, strsep, strtok, strtok_r...Here is a case where I have a delimiter and I want to split the string. Having only done so in languages such as Java, JavaScript, Python..it seems verbose and clumsy. It feels a bit fragile..Is there a better way to do this? I feel that I have to put a lot of trust in arithmetic.
char message [] = "apples are better than bananas...But good as grapes?";
char *delimiter_location = strstr(message, "...");
int m1_strlen = delimiter_location - message;
int m1_chararr_size = m1_strlen + 1;
char message_1 [m1_chararr_size];
memset(message_1, '\0', m1_chararr_size);
strncpy(message_1, message, m1_strlen);
printf("message: %s\n", message);
printf("message 1: %s", message_1);