If you really want to use (less portable) scanf_s
, from the C11 standard (n1570), Annex K 3.5.3.2 p.4:
The fscanf_s
function is equivalent to fscanf
except that the c
, s
, and [
conversion specifiers apply to a pair of arguments (unless assignment suppression is indicated by a *
). The first of these arguments is the same as for fscanf
. That argument is immediately followed in the argument list by the second argument, which has type rsize_t
and gives the number of elements in the array pointed to by the first argument of the pair.
You need to give the lengths of your char *
arguments:
scanf_s("%f %c %c", &inTemp, &inUnit, 1, &outUnit, 1);
Alternatively, just use scanf
:
scanf("%f %c %c", &inTemp, &inUnit, &outUnit);
And, as always, check the return values.
In general, as scanf
is somtimes useful for little quick-and-dirty programmes, it’s of less use for productive software, because handling errors is hard. Use fgets
and sscanf
/strtod
/strtol
/… instead.