-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy path4-9.c
More file actions
33 lines (26 loc) · 629 Bytes
/
4-9.c
File metadata and controls
33 lines (26 loc) · 629 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#define BUFFER_SIZE 100
char buffer[100];
int buffer_index = 0;
void unget_character(int character) {
if (buffer_index >= BUFFER_SIZE)
printf("\nUngetch : Too many characters");
else if (character != EOF)
buffer[buffer_index++] = character;
}
int get_character() {
if (buffer_index > 0)
return buffer[--buffer_index];
else
return getchar();
}
int main() {
unget_character(EOF);
char character;
while ((character = get_character()) != EOF) {
printf("%c", character);
}
return 0;
}