You are working with a pre-filled circular buffer of 10 elements.
The buffer is structured as:
typedef struct {
int buffer[10];
int head; // Write pointer
int tail; // Read pointer
int count; // Number of unread bytes
int capacity; // Always 10
} CircularBuffer;
Your Task
Implement this function:
void read_bytes(CircularBuffer *cb, int n);
This function should:
Example-1
Input: n = 4
Initial Buffer:
buffer = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
head = 3
tail = 7
count = 6
Output:
80 90 100 10
Tail: 1
Example-2
Input: n = 5
Same setup, but count = 2
Output:
80 90 NULL NULL NULL
Tail: 9
Input
4
Expected Output
80 90 100 10 Tail: 1