I’m trying to parse a line like
1 {2} {2,3} {4}
into 4 different character arrays
where 1 is ‘1’,’\0′
and the other numbers in brackets are each
‘2’
‘2’,’3′
‘4’
I’ve tried strtok with dilems ” \t}” and I’ve also tried sscanf passing it %s for the first column and “{%S}” for the remaining columns. Neither are giving me expected results. Can anyone give me a push in the right direction?
Your problem is that
%Sparses a space terminated word (so it reads the ‘}’ as part of the string.Will scan the characters between ‘{}’ into a buffer.
Note: you may also want to be careful about buffer overflow here.
But I would try and parse the numbers out individually.
Edit (to show in use)
With this code:
Then use like this: