Skip to content

Instantly share code, notes, and snippets.

@Dviejopomata
Created October 9, 2018 20:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Dviejopomata/44e1cf2a13bbbd7234331c0d402a6d23 to your computer and use it in GitHub Desktop.
Save Dviejopomata/44e1cf2a13bbbd7234331c0d402a6d23 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <stdio.h>
#include <string.h>
using namespace std;
int splitByDelim(char *str, char *delim, int *out) {
char *pt;
pt = strtok(str, delim);
int i = 0;
while (pt != nullptr) {
int a = atoi(pt);
out[i] = a;
i++;
pt = strtok(nullptr, ",");
}
return i;
}
int main() {
char str[] = "1,2,3,4,5,666,555";
int l[10];
int size = splitByDelim(str, ",", l);
printf("Size %d\n", size);
for (int i = 0; i < size; ++i) {
printf("Index=%d Value=%d\n", i, l[i]);
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment