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 destination[4][4];
sscanf(test, template, destination);
From an immediate glance this appears to not work, so is there an alternative method to doing 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.