C LinkedList not writing to pointer

C LinkedList not writing to pointer

For some reason whenever I try to write to “queue”, it does not actually write the new linked list. What am I doing wrong?

/*

    Khanh Nguyen

    CSE 1320, hw #8

    example file for demonstrating how to use functions required for this assignment

    to use this file, do the following:

    1)  download the following to your directory on omega:

      a) example-hw08.c  (this file)

      b) hw08-header.h

      c) hw08-source.o

    2) compile this file and link to the object file using

        gcc -std=c89 -pedantic example-hw08.c hw08-source.o

*/

#include <stdio.h>

#include <stdlib.h>

#include <string.h>

#include "hw08-header.h"    /*  note header  */

typedef struct node{

    int classNumber;

    char *className;

    struct node *next;

} Queue;

void parseCommand(char *cmd, Queue **queue);

int main(int argc, char* argv[])

{

    int i = 0;

    char *value = "go";

    int key;

    Queue *queues = calloc(3, sizeof(Queue));

    (queues)->next = NULL;

    (queues + (sizeof(Queue) * 1))->next = NULL;

    (queues + (sizeof(Queue) * 2))->next = NULL;

    if(argc != 2)

    {

        printf("  usage:  program_name positive_integern");

        printf("example:  ./example-hw08  123n");

        exit(1);

    }

    /**************  begin REQUIRED  **************/

    /*  put before logic.  DO NOT PUT IN A LOOP */

    key = atoi(argv[1]);

    initialize(key);

    /**************   end REQUIRED   **************/

    while(strcmp(value, "stop") != 0)

    {

        value = getString();

        parseCommand(value, &queues);

    }

    printf("%dn", (queues + 1)->classNumber);

}

void parseCommand(char *cmd, Queue **queue) {

  char *verb, *class, *name, *className;

  int queueNumber, classNumber;

  Queue *tempQueue = *queue, *node, *p;

  verb = strtok(cmd, ",");

  if(strcmp(verb, "stop") != 0) {

    if(strcmp(verb, "enqueue") == 0) {

      queueNumber = atoi(strtok(NULL, ","));

      class = strtok(NULL, ",");

      name = strtok(NULL, ",");

      className = strtok(class, " ");

      classNumber = atoi(strtok(NULL, " "));

      printf("%s enters line %d to register for %s %dn", name, queueNumber, className, classNumber);

      node = malloc(sizeof(queue));

      node->classNumber = classNumber;

      node->next = NULL;

      p = tempQueue;

      while(p->next != NULL) {

        p = p->next;

      }

      p->next = node;

      p = node;

      *queue = tempQueue;

    }

  }

}


"You need a similar assignment done from scratch? Our qualified writers will help you with a guaranteed AI-free & plagiarism-free A+ quality paper, Confidentiality, Timely delivery & Livechat/phone Support.


Discount Code: CIPD30



Click ORDER NOW..

order custom paper