#include <stdio.h>
#include <stdint.h>
void parse_csv_to_array(const char *str, uint8_t *arr, uint8_t *count) {
int i = 0, k = 0;
int start = 0;
while (str[i] != '\0') {
if (str[i] == ',' || str[i+1] == '\0') {
int end = (str[i] == ',') ? i : i+1;
if (end > start) { // only parse if non-empty
int value = 0;
for (int j = start; j < end; j++) {
value = value * 10 + (str[j] - '0');
}
arr[k++] = (uint8_t)value;
}
start = i + 1;
}
i++;
}
*count = k;
}
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