Hey...
I'm trying to use fscanf & fprintf in code compiled with Embedded Studio and run on a Nordic nRF52840.
I managed to derive that fprintf ultimately calls __write with a file handle as a parameter, and so I'm able to differentiate between stdout and stderr and send them to the correct UART.
But it is unclear how to create the correct code for scanf (or fscanf).
I created the workaround function as suggested in the manual (see below) and it works - but I had to make up my external declaration for __vfscanf and at the end of the day I'd just as soon use the built-in fscanf rather than a workaround.
Is there a way to find/populate the system equivalent of the iod below?
int uart0_scanf(const char *fmt, ...)
{
__stream_scanf_t iod;
va_list a;
int n;
va_start(a, fmt);
iod.is_string = 0;
iod.getc_fn = uart0_getc;
iod.ungetc_fn = uart0_ungetc;
n = __vfscanf((__stream_scanf_t *)&iod, (const unsigned char *)fmt, a);
va_end(a);
return n;
}
I'm trying to use fscanf & fprintf in code compiled with Embedded Studio and run on a Nordic nRF52840.
I managed to derive that fprintf ultimately calls __write with a file handle as a parameter, and so I'm able to differentiate between stdout and stderr and send them to the correct UART.
But it is unclear how to create the correct code for scanf (or fscanf).
I created the workaround function as suggested in the manual (see below) and it works - but I had to make up my external declaration for __vfscanf and at the end of the day I'd just as soon use the built-in fscanf rather than a workaround.
Is there a way to find/populate the system equivalent of the iod below?
int uart0_scanf(const char *fmt, ...)
{
__stream_scanf_t iod;
va_list a;
int n;
va_start(a, fmt);
iod.is_string = 0;
iod.getc_fn = uart0_getc;
iod.ungetc_fn = uart0_ungetc;
n = __vfscanf((__stream_scanf_t *)&iod, (const unsigned char *)fmt, a);
va_end(a);
return n;
}