-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy path4-7.c
41 lines (32 loc) · 755 Bytes
/
4-7.c
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
34
35
36
37
38
39
40
41
#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
buffer[buffer_index++] = character;
}
int get_character() {
if (buffer_index > 0)
return buffer[--buffer_index];
else
return getchar();
}
void unget_string(char string[]) {
int size = strlen(string);
while (size > 0)
unget_character(string[--size]);
}
int main() {
unget_string("abcdef");
char character;
do {
character = get_character();
printf("%c", character);
} while (character != 'f');
return 0;
}