#include <stdio.h>
#include <stdint.h>
int power(int num, int exp)
{
int result = 1;
while(exp--)
{
result *= num;
}
return result;
}
void parse_csv_to_array(const char *str, uint8_t *arr, uint8_t *count) {
// Your logic here
int len = -1;
while(str[++len] != '\0');
int idx = 0;
int num = 0;
int exp = 0;
int temp[255] = {0};
int x =0;
for(int i=0; i<len; ++i)
{
exp =0;
x= 0;
num = 0;
while((str[i] != ',') && (str[i] != '\0'))
{
temp[x++] = str[i] - '0';
i++;
}
for(int i=(x-1); i>=0; --i)
{
num += temp[i]*power(10,exp);
exp++;
}
arr[idx++] = num;
}
*count = idx;
}
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