I'm trying to sort a string into different variables in C (when I say string I mean char array). The string contains smaller 'blocks', separated by a tab, and I want sscanf to put the next 'block' into a string each time it is called.
For example, if the string is 00:00:00:00 12345 abcd, I want the first sscanf call to put 00:00:00:00 in a string, the next sscanf call to put 12345 in the string, etc.
I can't understand why my code doesn't work. I have sscanf(s, "%[^\t]%*c", buf), which (I think) should tell sscanf to read everything up to a tab character, and then the %*c tells it to read but discard the tab character (so that the next time sscanf is called, there is no leading tab character). There is never more than 1 tab character separating the blocks in the string.
I'm sure there is a better way of doing this than using sscanf, and that'd be great if someone told me, but I'd also like to figure this out too because it seems to be annoyingly easy and I don't know why it's not working. Thanks for your help
scanf()is evil, don't use it, it's an especially bad idea to use it for tokenizing.strchr(),strstr()andstrtok_r()are all better alternatives.