#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);
}
}
Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers of your data.