The problem is how you create the string.
Sorry my previous answer, I misunderstood your question:
Simply put, the declaration should be as follows:
char str[] = "1,2,3,4,5,6,7,8,9, 10, 12";
Then you can use strtok to split the string into an array of strings, omitting the delimiter (which is a comma in your case), then pass the members of the array to atoi
Now, why is your code not working?
Firstly, the characters must be surrounded by apostrophes, otherwise the compiler will take the number that you pass literally as an ASCII value.
Secondly, arrays in C: char str[] = {'1', '2', '3', '4', '5'}; does not mean a line separated by a comma, these commas are separated by ARRAY members, each in its own index, and not as a whole line.
source share