Can someone analyze my code and see what could be wrong ?. It's a simulation exercise I got to do in college. Error: The code executes, but it goes into looping. Whats the problem?
Code:
#include <stdio.h>
#include <stdlib.h>
#define N 10
int suc(int p){
int temp;
if (p==N)
temp=1;
else
temp=p+1;
return(temp);
}
void inserir(char F[], int i, int *f, int *over, int *c, char ch){
*over= 0;
if(suc(*f)==i){
printf("Overflow na fila\n");
*over=1;
}
else{
*f=suc(*f);
F[*f]=ch;
*c++;
}
}
char remover(char F[], int *i, int f, int *c){
char temp;
if(*i==f)
printf("Underflow na fila");
else
{ *i=suc(*i);
temp=F[*i];
*c++;
}
return(temp);
}
void exibirSomenteFila(char F[], int i, int f){
int x;
if (i == f)
printf ("\nFila vazia");
else
{ x=i;
while (x != f)
{ x = suc(x);
printf(" %c ",F[x]);
}
}
printf ("\n");
}
void main()
{
char F[N+1], ch;
int i,f, minutos, contador, ov, r, k ;
minutos=0;
i=1;
f=1;
contador=0;
ov=0;
while(contador<40){
minutos++;
if (minutos % 2==0){
inserir(F, i, &f, &ov, &contador, 'a');
if (ov==1){
printf("A area sera esvaziada");
exibirSomenteFila(F,i,f);
while (i != f){
ch=remover(F, &i, f, &c);
printf("%d", ch);
}
inserir(F, i, &f, &ov, &contador, 'a');
exibirSomenteFila(F,i,f);
}
}
if (minutos%3==0){
r=rand() % 3;
k=1;
while (k<=r){
ch=remover(F, &i, f, &contador);
printf("%c", ch);
k++;
}
}
if (minutos%8==0)
exibirSomenteFila(F,i,f);
}
exibirSomenteFila(F,i,f);
}