Thread: Queue function

  1. #1
    Registered User
    Join Date
    Oct 2008

    Lightbulb Queue function

    Suppose s structure function is defined as:
    typedef struct node {
                     char *name;
                     char phone[9];
                     struct node *next;
                     } queue;
    I need to write a function void insert_queue( queue **q_front, queue **q_rear, char *str, char str_num[]), such that *q_front point to the 1st node, *q_rear point to the last node. It adds new node with name str and phone str_num at the end queue while updating q_rear and q_front.

    I came out with the below definition but the program don't work. Hope anyone can spot my error. Thanks
    void insert_queue( queue **q_front, queue **q_rear, char *str, char str_num[]){
    * q_front= (queue*) malloc(sizeof (struct node));
    * q_front-> name= *str;
    * q_front-> phone= str_num;
    * q_front-> next= NULL;
    if (*q_rear !=NULL)
    *q_rear= *q_front;
    return *q_rear;

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Farncombe, Surrey, England
    * q_front= (queue*) malloc(sizeof (struct node));
    Don't cast malloc - it may hide problems, and nothing good ever comes from it.

    *q_rear= *q_front;
    Are you supposed to ALWAYS set this?

    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Help with FIFO QUEUE
    By jackfraust in forum C++ Programming
    Replies: 23
    Last Post: 04-03-2009, 08:17 AM
  2. In over my head
    By Shelnutt2 in forum C Programming
    Replies: 1
    Last Post: 07-08-2008, 06:54 PM
  3. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  4. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  5. Replies: 5
    Last Post: 02-08-2003, 07:42 PM