...
| Code Block | 
|---|
|  | 
| 
const char *filename = "test.txt";
FILE *fptr;
int c = getc(fptr = fopen(filename, "r"));
 | 
This non-compliant code example also violaties FIO33-C. Detect and handle input output errors resulting in undefined behavior.
Compliant Solution: getc()
...
| Code Block | 
|---|
|  | 
| 
const char *filename = "test.txt";
FILE *fptr = fopen(filename, "r");
if (fptr == NULL) {
  /* CheckHandle fptrError for validity */
}
int c = getc(fptr);
 | 
Non-Compliant Code Example: putc()
...
| Code Block | 
|---|
|  | 
| 
const char *filename = "test.txt";
FILE *fptr = fopen(filename, "w");
if (fptr == NULL) {
  /* Handle Error */
}
int c = 'a';
while (c <= 'z') {
  putc(c++, fptr);
}
 | 
...
| Code Block | 
|---|
|  | 
| 
const char *filename = "test.txt";
FILE *fptr = fopen(filename, "w");
if (fptr == NULL) {
  /* Handle Error */
}
int c = 'a';
while (c <= 'z') {
  putc(c, fptr);
  c++;
}
 | 
...