Created
October 9, 2018 20:59
-
-
Save Dviejopomata/44e1cf2a13bbbd7234331c0d402a6d23 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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