Hi everyone,
I am working on the piece of code below. It is supposed to allow the
user to insert 10 first names into a queue, then allow the user to
delete a name, and print the queue. I was able to compile the code,
run the program and enter the 10 first names in the queue. But then
the program "crashes": the program prints "error" infinitely many
times. I would appreciate if someone could help me identify the
problems.
Thanks a lot in advance for your help.
#include <stdio.h>
#define MAXNUM 10
#define MAXS 8
void insertq(void);
void deleteq(void);
void insertq(void);
void printq(void);
char q[MAXNUM][MAXS];
int h, t;
void main(void)
{
char response[MAXS];
h=-1;
t=-1;
printf("i/d/p/q");
scanf("%s", response);
while (response[0] != 'q' && response[0] != 'Q')
switch(response[0]){
case 'i':
insertq();
break;
case 'd':
deleteq();
break;
case 'p':
printq();
break;
default:
printf("error input i/p/d/q");
break;
}
printf("i/p/d/q");
scanf("%s", response);
}
void insertq(void)
{
char response[MAXS];
if (t-h+1 == MAXNUM)
printf("overflow \n");
else{
printf("enter name");
scanf("%s", response);
if(h==-1){
h=0;
t=-1;
}
}
}
void printq(void)
{
char response[MAXS];
int j;
printf("l or p");
scanf("%s", response);
if(response[0]=='l')
for (j=h; j<=t; j++)
printf("%d %s \n", j, q[j]);
if (response[0]=='p')
for (j=h; j<=MAXNUM; j++)
printf("%d %s \n", j, q[j]);
}
void deleteq(void)
{
if(h==-1)
printf("underflow \n");
else
printf("servicing %s \n", q[h++]);
if(h>t){
h=-1;
t=-1;
} }
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Microsoft DOTNET ASP, C++, SQL SERVER" group.
-------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
For stunning photoshop tutorials, visit:
www.psd-help.blogspot.com
-------------------------------------------------------------------------------------------------------------
-------------------------------------------------------------------------------------------------------------
-~----------~----~----~----~------~----~------~--~---