How to return values from a function with variable arguments

I try to develop a function that returns values to a variable list of arguments. Example:

char CIO_buffer [255];

uint8_t Rx_receive (const char* format, ...)
{
    uint8_t len;
    va_list argptr;
    
    va_start (argptr, format);
    len = sscanf (&CIO_buffer [4], format, argptr);
    va_end (argptr);
    return len;
} /*** Rx_receive ***/

I haver tried this code to fill the CIO_buffer (using vsprintf) and that works fine. The problem lies in calling the function. When I call this function like

Rx_receive ("%d %d", a, b);

a and b are not changed because it is a call by value. A call by reference

Rx_receive ("%d %d", &a, &b);

neither changes the values. And that leaves me with empty hands. I don't know to organize a call by pointer.

When I use sscanf directly all works right:

sscanf (&CIO_buffer [4], "%d %d", &a, &b)

a and b are changed as is expected. Something is wrong in transmitting the values.

Somebody has a solution?

Arnold

http://www.gammon.com.au/forum/?id=12607

The Arduino is a small device. Just use global variables.

...R

Rnold:     va_start (argptr, format);     len = sscanf (&CIO_buffer [4], format, argptr);     va_end (argptr);

You want the variable argument list version of scanf() here -- vscanf() see http://www.nongnu.org/avr-libc/user-manual/group__avr__stdio.html#ga8bd4b760f67791a54e73111734caa82f

gardner: You want the variable argument list version of scanf() here -- vscanf() see http://www.nongnu.org/avr-libc/user-manual/group__avr__stdio.html#ga8bd4b760f67791a54e73111734caa82f

@Gardner: you are right. Thanks to your remark I did some search and I should have used vsscanf: http://www.cplusplus.com/reference/cstdio/vsscanf/. And this one is not recognised by the Arduino compiler (it is, however, recognised by the Teensy compiler). The other versions of scanf are recognised. Is there some oversight from the Arduino team (or almost impossibly, from me ;-)) I hope I am doing something wrong.

Regards, Arnold