...
In this noncompliant code example, the programmer is attempting to overwrite the format string with a string value read in from stdin such as "%d%f 1 3.3" , and use the resulting modified string of "%s%d%f" to input the subsequent values of 1 and 3.3:
| Code Block | ||||
|---|---|---|---|---|
| ||||
#include <stdio.h> /* ... */ char format[100] = "%s"; int i; float x; int n = scanf(format, format + 2, &i, &x); |
...
The same results can be achieved as shown in this compliant solutoinsolution.
| Code Block | ||||
|---|---|---|---|---|
| ||||
#include <stdio.h> /* ... */ int i; float x; int n = fscanf(stdin, "%d%f", &i, &x); |
...