Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
bgColor#ffcccc
const char *filename = "test.txt";
FILE *fptr = fopen(filename, "w");

int c = 97'a';

while (c <= 123'z') {
  putc(c++, fptr);
}

Compliant Solution: putc()

...

Code Block
bgColor#ccccff
const char *filename = "test.txt";
FILE *fptr = fopen(filename, "w");

int c = 97'a';

while (c <= 123'z') {
  putc(c, fptr);
  c++;
}

This example only illustrates the side effect issue.  It is not portable to character sets that do not number their lower case letters consecutively.

Risk Assessment

Using an expression that has side effects as the argument to getc() or putc() can result in unexpected behavior and possibly abnormal program termination.

...