i get "customer_service_simulator.exe stopped" error, but i dont know why? this is my c programming project and i have limited time left before deadline. the code is:
#include <stdio.h>
#include <stdlib.h>
#include<time.h>
#define FALSE 0
#define TRUE 1
/*A Node declaration to store a value, pointer to the next node and a priority value*/
struct Node
{
int priority; //arrival time
int val; //type
int wait_time;
int departure_time;
struct Node *next;
};
Queue Record that will store the following:
size: total number of elements stored in the list
front: it shows the front node of the queue (front of the queue)
rear: it shows the rare node of the queue (rear of the queue)
availability: availabity of the teller
struct QueueRecord
{
struct Node *front;
struct Node *rear;
int size;
int availability;
};
typedef struct Node *niyazi;
typedef struct QueueRecord *Queue;
Queue CreateQueue(int);
void MakeEmptyQueue(Queue);
void enqueue(Queue, int, int);
int QueueSize(Queue);
int FrontOfQueue(Queue);
int RearOfQueue(Queue);
niyazi dequeue(Queue);
int IsFullQueue(Queue);
int IsEmptyQueue(Queue);
void DisplayQueue(Queue);
void sorteddequeue(Queue);
void sortedenqueue(Queue, int, int);
void tellerzfunctionz(Queue *, Queue, int, int);
int main()
{
int system_clock=0;
Queue waitqueue;
int exit, val, priority, customers, tellers, avg_serv_time, sim_time,counter;
char command;
waitqueue = CreateQueue(0);
srand(time(NULL));
fflush(stdin);
printf("Enter number of customers, number of tellers, average service time, simulation time\n:");
scanf("%d%c %d%c %d%c %d",&customers, &command,&tellers,&command,&avg_serv_time,&command,&sim_time);
fflush(stdin);
Queue tellerarray[tellers];
for(counter=0;counter<tellers;counter++){
tellerarray[counter]=CreateQueue(0); //burada teller sayisi kadar queue yaratiyorum
}
for(counter=0;counter<customers;counter++){
priority=1+(int)rand()%sim_time; //this will generate the arrival time
sortedenqueue(waitqueue,1,priority); //here i put the customers in the waiting queue
}
tellerzfunctionz(tellerarray,waitqueue,tellers,customers);
DisplayQueue(waitqueue);
DisplayQueue(tellerarray[0]);
DisplayQueue(tellerarray[1]);
// waitqueue->
printf("\n\n");
system("PAUSE");
return 0;
}
/*This function initialises the queue*/
Queue CreateQueue(int maxElements)
{
Queue q;
q = (struct QueueRecord *) malloc(sizeof(struct QueueRecord));
if (q == NULL)
printf("Out of memory space\n");
else
MakeEmptyQueue(q);
return q;
}
/*This function sets the queue size to 0, and creates a dummy element
and sets the front and rear point to this dummy element*/
void MakeEmptyQueue(Queue q)
{
q->size = 0;
q->availability=0;
q->front = (struct Node *) malloc(sizeof(struct Node));
if (q->front == NULL)
printf("Out of memory space\n");
else{
q->front->next = NULL;
q->rear = q->front;
}
}
/*Shows if the queue is empty*/
int IsEmptyQueue(Queue q)
{
return (q->size == 0);
}
/*Returns the queue size*/
int QueueSize(Queue q)
{
return (q->size);
}
/*Shows the queue is full or not*/
int IsFullQueue(Queue q)
{
return FALSE;
}
/*Returns the value stored in the front of the queue*/
int FrontOfQueue(Queue q)
{
if (!IsEmptyQueue(q))
return q->front->next->val;
else
{
printf("The queue is empty\n");
return -1;
}
}
/*Returns the value stored in the rear of the queue*/
int RearOfQueue(Queue q)
{
if (!IsEmptyQueue(q))
return q->rear->val;
else
{
printf("The queue is empty\n");
return -1;
}
}
/*Displays the content of the queue*/
void DisplayQueue(Queue q)
{
struct Node *pos;
pos=q->front->next;
printf("Queue content:\n");
printf("-->Priority Value\n");
while (pos != NULL)
{
printf("--> %d\t %d\n", pos->priority, pos->val);
pos = pos->next;
}
}
void enqueue(Queue q, int element, int priority){
if(IsFullQueue(q)){
printf("Error queue is full");
}
else{
q->rear->next=(struct Node *)malloc(sizeof(struct Node));
q->rear=q->rear->next;
q->rear->next=NULL;
q->rear->val=element;
q->rear->priority=priority;
q->size++;
}
}
void sortedenqueue(Queue q, int val, int priority)
{
struct Node *insert,*temp;
insert=(struct Node *)malloc(sizeof(struct Node));
insert->val=val;
insert->priority=priority;
temp=q->front;
if(q->size==0){
enqueue(q, val, priority);
}
else{
while(temp->next!=NULL && temp->next->priority<insert->priority){
temp=temp->next;
}
//printf("%d",temp->priority);
insert->next=temp->next;
temp->next=insert;
q->size++;
if(insert->next==NULL){
q->rear=insert;
}
}
}
niyazi dequeue(Queue q)
{
niyazi del;
niyazi deli;
del=(niyazi)malloc(sizeof(struct Node));
deli=(niyazi)malloc(sizeof(struct Node));
if(IsEmptyQueue(q)){
printf("Queue is empty!");
return NULL;
}
else
{
del=q->front->next;
q->front->next=del->next;
deli->val=del->val;
deli->priority=del->priority;
free(del);
q->size--;
return deli;
}
}
void sorteddequeue(Queue q)
{
struct Node *temp;
struct Node *min;
temp=q->front->next;
min=q->front;
int i;
for(i=1;i<q->size;i++)
{
if(temp->next->priority<min->next->priority)
{
min=temp;
}
temp=temp->next;
}
temp=min->next;
min->next=min->next->next;
free(temp);
if(min->next==NULL){
q->rear=min;
}
q->size--;
}
void tellerzfunctionz(Queue *a, Queue b, int c, int d){
int i;
int value=0;
int priority;
niyazi temp;
temp=(niyazi)malloc(sizeof(struct Node));
if(c==1){
for(i=0;i<d;i++){
temp=dequeue(b);
sortedenqueue((*(a)),temp->val,temp->priority);
}
}
else{
for(i=0;i<d;i++){
while(b->front->next->val==1){
if((*(a+value))->availability==1){
temp=dequeue(b);
sortedenqueue((*(a+value)),temp->val,temp->priority);
(*(a+value))->rear->val=2;
}
else{
value++;
}
}
}
}
}
//end of the program