Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: minor update to new CS

...

If more than one character needs to be pushed by ungetc(), then fgetpos() and fsetpos() should be used before and after reading the data instead of pushing it back with ungetc(). Note that this solution can only be used if the input is seekable.

Code Block
bgColor#ccccff
FILE* fptr = fopen(file_name, "rb");
fpos_t pos;

if (fptr == NULL) {
  /* Handle Error */
}

/* Read data */

if(fgetpos(fptr, &pos)) {
  /* Handle Error */
}

/* Read the data that will be "pushed back" */

if(fsetpos(fptr, &pos)) {
  /* Handle Error */
}

/* Continue on */

...