Possible to replace sscanf arguments with array?

What you're trying to do is not possible with sscanf . You will have to loop it.

Up vote 0 down vote favorite share g+ share fb share tw.

I have a string of characters that is something like " asdf + lghd + ewre + fdsf + ..." that is of varying length. From this I also have a template for use with the sscanf function that is similar to "%s + %s + %s + ...". Because both of these are of varying lengths, is it possible to replace those additional arguments in sscanf where the values are to be stored with a dynamic array of strings?

For example: char *test = "adfe + asdf + fghe + jklo"; char *template = "%s + %s + %s + %s"; char destination44; sscanf(test, template, destination); From an immediate glance this appears to not work, so is there an alternative method to doing this? C split sscanf link|improve this question asked 15 mins agoa sandwhich652320 93% accept rate.

What you're trying to do is not possible with sscanf. You will have to loop it.

No. Sscanf, like all the xxxxxf functions in 'C' work by having a variaable number of aruments in the argument list. If you're looking for 4 strings (4 %s), the function expects 4 arguments that are character arrays.

In your example, you are providing a single argument that is an array of 4 character arrays. One way that would work would be for you to parse out the input using whatever separator you are using. Look at the functions substr and pos for some hints on how to do this.

Sscanf() doesn't support this, but you could write your own version of scanf. I've done this already in C# and posted the code here. Perhaps my code will give you some ideas for writing a custom version in C.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions