The program below isn't executing correctly. It should add names to the queue when you choose insert. Instead, if I choose insert it just repeatedly prompts me until the queue is full (then tells me queue full). I'm thinking it's a problem in my while loop, but I can't figure out where. Any help would be greatly appreciated.
Code:#include <stdio.h> #define MAXIMUM 10 #define MAXS 8 char q[MAXIMUM][MAXS]; int h, t; int main() { char response[MAXS]; int h, t = - 1; printf("Insert, delete, print, or quit?"); scanf("%s", &response); void insertq(void); void moveq(void); void deleteq(void); void printq(void); while(response[0] != 'q' && response[0] != 'Q') { switch(response[0]) { case 'I': case 'i': insertq(); break; case 'D': case 'd': deleteq(); break; case 'P': case 'p': printq(); break; default: printf("Bad input"); break; printf("Insert, delete, print, or quit?"); scanf("%s", &response); } } printf("End of job"); return 0; } void insertq(void) { char response[MAXS]; if(t - h + 1 == MAXIMUM) printf("Overflow"); else { printf("Enter your name \n"); scanf("%s", &response); if(h == -1) { h = 0; t = -1; } if(t == MAXIMUM - 1) moveq(); } } void moveq(void) { int j; for(j = 0; j <= t - h; j++) { strcpy(q[j], q[h+j]); t = t - h; h = 0; } } void deleteq(void) { if(h == -1) printf("Underflow"); else { printf("Servicing %s \n", q[h++]); if(h > t) { h = -1; t = -1; } } } void printq(void) { char response[MAXS]; int j; char L, l, P, p; printf("Logical or physical? \n"); scanf("%s", &response); if(response[0] == L || response[0] == l) { for(j = h; j <= t; j++) printf("%d %s \n", j, q[j]); } if(response[0] == P || response[0] == p) { for(j = 0; j < MAXS; j++) printf("%d %s \n", j, q[j]); } }



LinkBack URL
About LinkBacks


