#include <stdio.h>
#include <semaphore.h>

#define MAX_BUFFER_SIZE 100

int buffer[MAX_BUFFER_SIZE];
int capacity;
int count = 0;

sem_t full;
sem_t empty;
sem_t mutex;

void produce() {
    sem_wait(&empty);
    sem_wait(&mutex);
    buffer[count] = 1;
    count++;
    printf("Produced 1 item, %d slots available\n", capacity - count);
    sem_post(&mutex);
    sem_post(&full);
}

void consume() {
    sem_wait(&full);
    sem_wait(&mutex);
    count--;
    printf("Consumed 1 item, %d slots available\n", capacity - count);
    sem_post(&mutex);
    sem_post(&empty);
}

int main() {
    sem_init(&full, 0, 0);
    sem_init(&empty, 0, capacity);
    sem_init(&mutex, 0, 1);

    printf("Enter capacity of buffer: ");
    scanf("%d", &capacity);

    char choice;
    while (1) {
        printf("Enter P to produce or C to consume: ");
        scanf(" %c", &choice);

        if (choice == 'P') {
            produce();
        } else if (choice == 'C') {
            consume();
        } else {
            break;
        }
    }

    sem_destroy(&full);
    sem_destroy(&empty);
    sem_destroy(&mutex);
    return 0;
}
After I enter 'P' or 'C' this stops working ?