I THINK MY MISTAKE IS IN THE MAIN FUNCTION. CAN SOMEBODY PLEASE HELP ME?
Code:
#include<stdio.h>
#include<conio.h>
#include<windows.h>
#include<stdbool.h>
#include<string.h>
#define N 6
typedef struct{
char pn[N];
int dur;
}PROCESS;
typedef struct{
PROCESS que[N];
int head;
int tail;
}QUE;
PROCESS getInput(int);
void createQ(QUE *);
void addQ(QUE *, PROCESS);
PROCESS delQ(QUE *);
bool emptyQ(int, int);
bool fullQ(int, int);
int main(void){
int i, j;
QUE input;
PROCESS data;
bool isFull, isEmpty;
createQ(&input);
for(i=0;i<N-1;i++){
data=getInput(i);
isFull=fullQ(input.head,input.tail);
if(isFull){
printf("Error: Queue is full.");
return;
}
else
addQ(&input,data);
}
isEmpty=emptyQ(input.head,input.tail);
while(!isEmpty){
data=delQ(&input);
printf("Processing %s ", data.pn);
if(data.dur>10){
for(j=0;j<data.dur;j++){
printf(".");
Sleep(1000);
}
data.dur=data.dur-10;
printf("Remaining time after processing is: %d", data.dur);
addQ(&input,data);
}
else{
for(j=0;j<data.dur;j++){
printf(".");
Sleep(1000);
}
}
}
printf("\nProcessing complete!");
getch();
return 0;
}
PROCESS getInput(int i){
PROCESS input;
printf("Input a process name (%d): ", i+1);
scanf("%s", input.pn);
printf("Input duration of process: ");
scanf("%d", &input.dur);
if(input.dur<=0){
do{
printf("Please input a number greater than zero: ");
scanf("%d", &input.dur);
}while(input.dur<=0);
}
printf("\n");
return input;
}
void createQ(QUE *q){
int i;
for(i=0;i<N;i++){
strcpy(q->que[i].pn," ");
q->que[i].dur=0;
}
q->head=0;
q->tail=0;
return;
}
void addQ(QUE *q, PROCESS data){
q->que[q->tail]=data;
if(q->tail==(N-1))
q->tail=0;
else
q->tail++;
}
PROCESS delQ(QUE *q){
PROCESS r;
r=q->que[q->head];
strcpy(q->que[q->head].pn," ");
q->que[q->head].dur=0;
if(q->head==(N-1))
q->head=0;
else
q->head++;
return r;
}
bool emptyQ(int head, int tail){
if(head==tail)
return true;
else
return false;
}
bool fullQ(int head, int tail){
if(head==((tail+1)%N))
return true;
else
return false;
}