I have a problem with the following code. The exercise tries to simulate a row that has random number of people passing through three boxes, when a box is empty an element is removed from the original row and goes to box C1, C2 or C3 and once there after a delay the value of the number that is in any of those three boxes decreases; when that value is zero, it is removed from the box and remains empty so that another element of the original row enters the other. The problem is that when I run, the boxes show me garbage and according to me that should not happen.
void caja(FILA *F)
{
FILA C1, C2, C3; crearFila(&C1); crearFila(&C2); crearFila(&C3);
TipoDato a, b, c;
do
{
x=dequeue(F);
Sleep(2000);
if (filaVacia(C1))
{
enqueue(&C1, x);
if (a==0)
{
dequeue(&C1);
}
}
else if (filaVacia(C2))
{
enqueue(&C2, x);
if (b==0)
{
dequeue(&C2);
}
}
else if (filaVacia(C3))
{
enqueue(&C3, x);
if (c==0)
{
dequeue(&C3);
}
}
system("cls");
printf("\nFila: \n");
imprime(*F);
printf("\nCaja 1: \n");
imprime(C1);
printf("\nCaja 2: \n");
imprime(C2);
printf("\nCaja 3: \n");
imprime(C3);
if (!filaVacia(C1))
{
a=dequeue(&C1); a--; enqueue(&C1, a);
}
if (!filaVacia(C2))
{
b=dequeue(&C2); b--; enqueue(&C2, b);
}
if (!filaVacia(C3))
{
c=dequeue(&C3); c--; enqueue(&C3, c);
}
}while(!filaVacia(*F));
printf("\n");
}