- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
ungetc() in C/C++
The function ungetc() takes a character and pushes it back to the stream so that the character could be read again.
Here is the syntax of ungetc() in C language,
int ungetc(int character, FILE *stream)
Here,
character − The character to be pushed back to stream.
stream − The pointer to the file object.
Here is an example of ungetc() in C language,
Example
#include <stdio.h> int main() { int c; while ((c = getchar()) != '0') putchar(c); ungetc(c, stdin); c = getchar(); putchar(c); puts(""); printf("The End!"); return 0; }
Output
s a b c t h 0 The End!
In the above program, a character of int type is declared. It will read the characters until 0/zero encounters. It will display characters and as zero encounters, it prints “The End!”.
int c; while ((c = getchar()) != '0') putchar(c); ungetc(c, stdin) c = getchar(); putchar(c); puts(""); printf("The End!");
- Related Articles
- fseek() in C/C++
- strcpy() in C/C++
- strcmp() in C/C++
- strcoll() in C/C++
- isless() in C/C++
- islessgreater() in C/C++
- Assertions in C/C++
- Errors in C/C++
- Arrays in C/C++?
- isgreater() in C/C++
- modf() in C/C++
- isblank() in C/C++
- islessequal() in C/C++
- strxfrm() in C/C++
- Comments in C/C++

Advertisements