C: sscanf but number of variables unknown
Hya,
Goal:
assign integers into array form string.
From string
"123,456,789,0123,4567,8901" (comma separated 6 integer numbers)
To array
a[0] = 123; a[1] = 456 ....a[5] = 8901
Idea is sscanf(string,"%d%d%d...",&(a[0]),&(a[1]),&(a[2])...)
Problem is that array size is unknown until the string is available for scanning. It could be huge.
What I thought:
Sounds like file scanning, it is easy. But, scanning same string gives me same value.
Umm.. vscanf or something else would do, once format string is determined. Yes, the format string can be made without any trouble. but how to pass variable??
What I did:
scan one variable, then manipulate string to clear fields from top to comma, scan next variable. (loop)
Assessment:
My way works, however, is there any smarter way?
Happy Penguins!
|