#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define MAX_TOKENS 64
#define TOKEN_LEN 32
void splitByDelimiters(const char* input, const char* delimiters, char tokens[][TOKEN_LEN], int* count) {
char temp[strlen(input) + 1];
strcpy(temp, input);
char* token = strtok(temp, delimiters);
*count = 0;
while (token != NULL && *count < MAX_TOKENS) {
int tlen = strlen(token);
strncpy(tokens[*count], token, tlen);
tokens[*count][tlen] = '\0'; // Ensure null-termination
(*count)++;
token = strtok(NULL, delimiters);
}
}
int main() {
const char* input = "abc,defg;hijk|lmnop-qrst_uvwxyz";
const char* delimiters = ",;|-_";
char tokens[MAX_TOKENS][TOKEN_LEN];
int tokenCount = 0;
splitByDelimiters(input, delimiters, tokens, &tokenCount);
for (int i = 0; i < tokenCount; ++i) {
printf("%s\n", tokens[i]);
}
return 0;
}
/*
run:
abc
defg
hijk
lmnop
qrst
uvwxyz
*/