Home > Blockchain >  queue list C program works but only shows 1 of the variables it's supposed to
queue list C program works but only shows 1 of the variables it's supposed to

Time:10-21

so my program is suppose to receive 4 strings and one int input by the user and store them in a struct node and put them in a queue list and you have a menu that can delete the node at the front or check the info of each of them but for some reason only the Int variable is shown and the other variables that are stored in char[] don't show up. I tried putting the print function on diferent places and also try to use diferent ways to call the info but none help. heres some exceprts from the code and heres a link to it in full https://hastebin.com/isahijoyer.cpp

            case 3: 
            val = peek(q);
            if (val != -1)
                printf("\nAs informações do Aviao no inicio da fila são:\n");
                printf("ID: %s\t", q->front->id);
                printf("Numero De Passageiros: %d\t", val);
                printf("Destino:  %s\t", q->front->des);
                printf("Empressa: %s\t", q->front->comp);
                printf("Modelo: %s\t", q->front->mod);
                
            break;
        case 4: 
            q = display(q);
            break;
        case 5: 
            printf("Quantidade de avioes esperando eh: %d\t", cont);
            break;
    }

        struct queue *display(struct queue *q)
            {
                struct node *ptr;
                ptr = q -> front;
                if(ptr == NULL)
                    printf("\nA FILA ESTA VAZIA\n");
                else
                {
                    printf("\n");
                    while(ptr!=q -> rear)
                    {
                     printf("ID: %s\t", ptr -> id);
        
                        ptr = ptr -> next;
                    }
                    printf("ID: %s\t", ptr -> id);
                return q;
            }
            }

CodePudding user response:

struct queue *insert(struct queue *q,int val,char ide[10],char dest[10],char compa[10],char mode[10])
{
    struct node *ptr;
    ptr = (struct node*)malloc(sizeof(struct node));
    ptr -> pass = val;
    strcpy(ide, ptr->id);
    strcpy(dest, ptr->des);
    strcpy(compa, ptr->comp);
    strcpy(mode, ptr->mod);

The first parameter to strcpy is the destination.

  •  Tags:  
  • c
  • Related