Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <string.h>
- /* Returns: array of decoded values. [0] - count of values */
- int *decode(char *encoded) {
- int idx = 1;
- int maxlen = 8;
- char *token;
- char *delim = " :;,|";
- int *nums = malloc(maxlen * sizeof(int));
- /* Preserve the original string */
- encoded = strdup(encoded);
- token = strtok(encoded, delim);
- nums[1] = atoi(token);
- while (token = strtok(NULL, delim)) {
- if (idx >= maxlen) {
- maxlen += 8;
- nums = realloc(nums, maxlen * sizeof(int));
- }
- nums[++idx] = atoi(token);
- }
- nums[0] = idx;
- return nums;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement