This repository has been archived on 2024-12-16. You can view files and clone it, but cannot push or open issues or pull requests.
CodeBlocksPortable/WATCOM/samples/clibexam/ungetc.c

21 lines
366 B
C

#include <stdio.h>
#include <ctype.h>
void main()
{
FILE *fp;
int c;
long value;
fp = fopen( "file", "r" );
value = 0;
c = fgetc( fp );
while( isdigit(c) ) {
value = value*10 + c - '0';
c = fgetc( fp );
}
ungetc( c, fp ); /* put last character back */
printf( "Value=%ld\n", value );
fclose( fp );
}