0

How do I create a queue that can insert and delete more than one data value with the data value being string? Please and thanks

Here's my program it's still not working the way I want it to #include<stdio.h> #include<string.h> #include<stdlib.h> # define max 50 typedef struct patient_data{ char fname[10],lname[10],address[10],condition[10],symptoms[12]; int patient_num; }; queue[max]; int insq(char queue[max][80], int *rear, char p_data[80]) { if(*rear == max -1) return(-1); else { *rear = *rear + 1; strcpy(queue[*rear], p_data); return(1); } } int delq(char queue[max][80], int *front, int *rear, char p_data[80]) { int i; if ((front==-1) && (rear==-1)) { printf("\nQueue is empty no elements to delete"); return; } for (i = 0; i <= rear; i++) { if (p_data == queue[i]) { for (; i < rear; i++) { queue[i] = queue[i + 1]; } queue[i] = -99; rear--; if (rear == -1) front = -1; return; } } printf("\n%d not found in queue to delete", p_data); /*if(*front == *rear) return(-1); else { (*front)++; strcpy(p_data, queue[*front]); return(1); }

30th Mar 2020, 10:15 PM
Tyrese Morgan
Tyrese Morgan - avatar
3 Réponses
+ 1
Oh no,i wasn't aware of this thanks
31st Mar 2020, 1:47 AM
Tyrese Morgan
Tyrese Morgan - avatar
0
this is what I have to display the queue: void display_pqueue(char queue[max][80], int *front, int *rear, char p_data[80]) { if ((front == -1) && (rear == -1)) { printf("\nQueue is empty"); return; } for (; front <= rear; front++) { printf(" %s ", p_data[front]); } front = 0;
30th Mar 2020, 10:16 PM
Tyrese Morgan
Tyrese Morgan - avatar
0
this is the main still not quite finished int main() { struct patient_data p_data; char queue[max][80],fname[10],lname[10],address[10],condition[10],symptoms[12]; int front, rear, reply, patient_num; int ch; front = rear = -1; //... Initialize a Queue printf("------------------------------\n"); printf("\tMenu"); printf("\n------------------------------"); printf("\n 1. Insert a patient record"); printf("\n 2. Delete a paiient record"); printf("\n 3. Display patient record in the System"); printf("\n 4. Exit"); printf("\n------------------------------\n"); while(1) { printf("Choose operation : "); scanf("%d", &ch); switch(ch) { case 1 : // insert printf("\nEnter patient first name : "); scanf("%s",fname); printf("\nEnter patient last name:"); scanf("%s",lname); printf("\nEnter patient number:"); scanf("%d",&patient_num); printf("\nEnter patient address:"); scanf("%s",address); printf("\nEnter patient Symptoms:"); scanf("%s",symptoms); printf("\nEnter patient conditions:"); scan
30th Mar 2020, 10:18 PM
Tyrese Morgan
Tyrese Morgan - avatar