Itβs impossible to figure out how variable lists work under covers (and therefore turn your code into non-portable), there is no way to change the arguments.
But I had one thought that may or may not work. I have not tested it, since I really don't think you should use it, but if you are damn tuned for it, this may help.
Since you just want to get the number of characters scanned, you should understand that you do not need to do this at the same time as the actual setting of the callerβs variables.
Ask your code to check the line to give arguments as necessary to the caller. No changes are required at all.
The next step is a bit complicated.
Count the number of % characters in the format string, which is not immediately followed by % or * - in other words, the number of variables to be sent to sscanf . Approve if it is more than your upper limit (see Code below).
Then add the %n sequences to the end of the format string to make sure you get the number of characters.
Then, using your new format string, use the spam buffer (repeatedly) to get all values ββfrom the scan, including the last one (number of characters).
Something like this (you are responsible for debugging):
typedef union { char junk[512]; // Be *very* careful with "%s" buffer overflows. int length; } tJunkbuff; int newSscanf (char **str, const char *format, ...) { int rv, length; char buf[MAX_LENGTH]; tJunkBuff junkbuff; va_list args; // Populate variables. va_start (args, format); rv = vsscanf (*str, buf, args); va_end (args); // Get length. // String scanning for % count and assert/error left out. // Only 20 allowed (depends on number of jb.junk variables below (n-1)). strcpy (buf, format); strcat (buf, "%n"); sscanf (*str, buf, jb.junk,jb.junk, jb.junk, jb.junk, jb.junk, jb.junk,jb.junk, jb.junk, jb.junk, jb.junk, jb.junk,jb.junk, jb.junk, jb.junk, jb.junk, jb.junk,jb.junk, jb.junk, jb.junk, jb.junk, jb.junk); // May need to be "&(jb.junk)" ? *str += jb.length; return rv; }
I would be interested to hear how this happens if you decide to do it. This is my job (and responsibility). I'm glad to sell you a chainsaw, but if you cut off your leg when using it, then your problem :-)