#include <stdio.h>
#include <stdint.h>
int convert_arr(char *s,char *e){
int res = 0;
while(s<=e){
res = res*10 + (*s - '0');
s++;
}
return res;
}
void parse_csv_to_array(char *str, uint8_t *arr, uint8_t *count) {
char *start = str;
char *end;
int i = 0;
while(*str){
if(*str == ','){
end = str-1;
arr[i++] = convert_arr(start,end);
start = str+1;
}
str++;
}
arr[i++] = convert_arr(start,str-1);
*count = i;
}
int main() {
char str[101];
fgets(str, sizeof(str), stdin);
// Remove newline
uint8_t i = 0;
while (str[i]) {
if (str[i] == '\n') {
str[i] = '\0';
break;
}
i++;
}
uint8_t arr[20];
uint8_t count = 0;
parse_csv_to_array(str, arr, &count);
for (uint8_t i = 0; i < count; i++) {
printf("%u", arr[i]);
if(i < count - 1){
printf(" ");
}
}
return 0;
}
Input
10,20,30
Expected Output
10 20 30