I want to convert a comma separated char* to an uint32_array[] in C. Is there an easy method/routine to do that?
I already spend a lot of time on SO and found many solutions on C++, but not an C like that : Parsing a comma-delimited std::string But I think it is not a good solution to cast from char* to string to string stream to vector and work with the vector.
char input[] = "1 , 2 , 34, 12, 46, 100";
to
uint32_t output[] = { 1 , 2 , 34, 12, 46, 100 };
I would appreciate any kind of help. Thanks a lot.
Here's a recursive algorithm that only makes a single pass. It allocates at the deepest level and fills in on the way out:
Call with: