Hi, I have included ample explanatory comments in my code, so I think it will be most efficient just to post it to you:
Code:
#include "Queue.h"
int main(void)
{
QueueT Queu;
QueueT *pQS;
pQS = &Queu;
initQueue(pQS);
char insChr;
int menuSelection = 0;
int *ptrMS = &menuSelection;
//main menu
printf("\n\nProgram has been initialized.\n");
printf("Size:%d\nHead:%d\nTail:%d\n",pQS->size,pQS->head,pQS->tail);
while (menuSelection != 7)
{
printf("\n\nMenu:\n1:insertQueue\n2:removeQueue\n3:peekQueue\n4:isEmptyQueue\n");
printf("5:isFullQueue\n6:displayQueue\n7:Exit program\n");
printf("Please enter your selection followed by the enter key.\n");
scanf("%d",&menuSelection);
//ATTN: coding help section comment
//There is a DEATH PIT for scanf character statements here. I simply cannot get any to
//function here or anywhere beyond here in this while statement.
//Let me be clear that any reasonable place before the above
//scanf("%d",&menuSelection); statement is working fantastic but the minute I
//go past this line, it no longer works.
switch(menuSelection)
{
case 1:
//ATTN: coding help section comment
//The below two statements don't work at all. In the program, it just skips this completely.
printf("Please enter the character to be added to the queue:\n");
scanf("%c",&insChr);
//debugging printf below to test for performance;fails, also skipped in output.
printf("%c",insChr);
insertQueue(pQS,insChr);
//If I try to go ahead and do these operations in the inserQueue function
//instead, it continues to fail miserably.
//I can declare the variables inside of the function, but
//any time I try to access any part of "insChr", the operation immediately
//resumes failing.
//I would declare them inside of the function and say crisis
//averted but this is for a project.
break;
case 3:
printf("The next item in the queue is:\n");
peekQueue(pQS);
break;
case 4:
printf("1 indicates empty, 0 indicates that the queue is not empty\n%d\n",isEmptyQueue(pQS));
break;
case 5:
printf("1 indicates full, 0 indicates the queue is not full\n%d\n",isFullQueue(pQS));
break;
case 6:
printf("The queue contains the following items:\n");
displayQueue(pQS);
break;
}
system("Pause");
}
//Tests the size, head and tail to make sure Circular Buffer was initialized
//properly.
return 0;
}