deqeue

This is a discussion on deqeue within the C Programming forums, part of the General Programming Boards category; M.BM has number of items in inventory, and Q.front->BM has number of items user wants. After run this function M.BM ...

  1. #1
    Registered User
    Join Date
    Sep 2002
    Posts
    32

    deqeue

    M.BM has number of items in inventory, and Q.front->BM has number of items user wants. After run this function M.BM should subtract number of items that user wants.
    but, after run this function my inventory stays same.

    also, when I enqueue ABC and 2, the function nextline() prints ? -8989283

    Code:
    void nextline()
    {
    int i;
    
    i = dequeuedata();
    printf("%c  %i" , name, i);
    
    }
    Code:
    int dequeuedata()
    {
    	int i;
    	struct customer * tempPtr;
    
         if(isEmpty(Q))
    	 {
    	 printf("No More Orders\n");
    	
    	 }
    	strcpy(name, Q.front->firstname); 
       /* name is a global variable declared as char name[25] */
                      
    	switch(ch) /* ch is a global variable */
    	{
    	case '1': 
    	i= Q.front->BM;
    	M.BM -= Q.front->BM;
    	break;
    	
              	}
    	tempPtr = Q.front;
    
    	Q.front = Q.front->next;
    	if (Q.front == NULL)
    		Q.rear = NULL;
    	free (tempPtr);
    
    	return i;
    }

  2. #2
    Me want cookie! Monster's Avatar
    Join Date
    Dec 2001
    Posts
    680
    Because i is not initialized or changed (if ch != '1') in the dequeuedata function.

    In dequeuedata initialize your variable:
    Code:
    int dequeuedata()
    {
       int i = -1;
       ...

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. help!!
    By George in forum C Programming
    Replies: 1
    Last Post: 07-16-2003, 03:11 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21