...
Note that the range is in terms of character code values, and on an EBCDIC platform it will include some non-alphabetic codes. Consequently the isalpha()
function should be used to verify the input.
Non-Compliant Code Example
Mismatches between arguments and conversion specifiers may result in undefined behavior. Many compilers can diagnose type mismatches in formatted output function invocations.
Code Block | ||
---|---|---|
| ||
char const *error_msg = "Resource not available to user.";
int error_type = 3;
/* ... */
printf("Error (type %s): %d\n", error_type, error_msg);
|
Compliant Solution
This compliant solution ensures that the format arguments match their respective format specifiers.
Code Block | ||
---|---|---|
| ||
char const *error_msg = "Resource not available to user.";
int error_type = 3;
/* ... */
printf("Error (type %d): %s\n", error_type, error_msg);
|
...