#include <stdio.h>
int ungetc (
int iChar, /* character to store */
FILE* stream); /* file stream */
Description
The function ungetc stores a character back into the data
stream. The parameter iChar defines the character
to store. The parameter stream is a file pointer
defining the data stream to write to.
The function is included in the library RL-FlashFS. The prototype
is defined in the file stdio.h.
The function can be invoked only once between function calls that
read from the data stream. Subsequent calls to ungetc fail
with an EOF return value.
#include <rtl.h>
#include <stdio.h>
void main (void) {
int c;
FILE *fin;
fin = fopen ("Test.txt","r");
if (fin != NULL) {
while ((c = fgetc (fin)) == ' '); // Skip leading spaces
ungetc (c, fin); // Unget the first non-space
ungetc (c, fin); // This call fails with EOF. The file cursor
// is now positioned to a non-space character
fclose (fin);
}
}
This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.
ARM websites use two types of cookie: (1) those that enable the site to function and perform as required; and (2) analytical cookies which anonymously track visitors only while using the site. If you are not happy with this use of these cookies please review our Privacy Policy to learn how they can be disabled. By disabling cookies some features of the site will not work.