printing summay linked list

Discussion in 'C' started by musicmancanora4, May 18, 2006.

  1. musicmancanora4

    musicmancanora4 New Member

    Joined:
    Mar 9, 2006
    Messages:
    42
    Likes Received:
    0
    Trophy Points:
    0
    Hey guys just like to ask a question how i could use the variable drinkType
    to access either hot or cold drinks depending on what they choose in the menu selection.

    To choose 1 or 2 the same function will run but i need it to just execute
    a certain part if they where to choose hot for example. If they choose cold i would need to run only the statements that print the cold and not the hot.

    Both options have to call the same function though

    Iv written a do while in my main to choose either
    1 Hot Drinks Summary
    2 Cold Drinks Summary

    if they press 1 or 2 it suppose to run the function below and print out



    Code:
    /**************************************************  **************************
    * Menu option #1: Display Summary
    * Allows the user to display a summary of all hot or cold drink categories
    * and items.
    **************************************************  **************************/
    void displaySummary(GJCType* menu, char drinkType)
    {
    
      /*  CategoryTypePtr currentCat;
        ItemType currentItem;
        
        
        assert(menu != NULL);
        
        currentCat = menu->headCategory;
        
        while(currentCat !=NULL)
        {
            
            currentCat= currentCat->nextCategory;
        }
        print the summary of the list*/
        
       
    
    
    
    }
    
    
    
    Code:
    #ifndef GJC_H
    #define GJC_H
    
    /* System-wide header files. */
    #include <stdio.h>
    #include <stdlib.h>
    #include <assert.h>
    #include <string.h>
    
    /* System-wide constants. */
    #define ID_LEN 5
    #define MIN_NAME_LEN 1
    #define MAX_NAME_LEN 25
    #define MIN_DESC_LEN 1
    #define MAX_DESC_LEN 250
    #define NUM_PRICES 3
    #define HOT 'H'
    #define COLD 'C'
    #define ERRORCODE 1
    #define BUFFER_SIZE 800
    #define NC_ARRAY_SIZE 500
    #define TRUE 1
    #define FALSE 0
    
    
    typedef struct category* CategoryTypePtr;
    typedef struct item* ItemTypePtr;
    
    /* Structure definitions. */
    typedef struct price
    {
       unsigned dollars;
       unsigned cents;
    } PriceType;
    
    typedef struct item
    {
       char itemID[ID_LEN + 1];
       char itemName[MAX_NAME_LEN + 1];
       PriceType prices[NUM_PRICES];
       char itemDescription[MAX_DESC_LEN];
       ItemTypePtr nextItem;
    } ItemType;
    
    typedef struct category
    {
       char categoryID[ID_LEN + 1];
       char categoryName[MAX_NAME_LEN + 1];
       char drinkType;      /* (H)ot or (C)old. */
       char categoryDescription[MAX_DESC_LEN];
       CategoryTypePtr nextCategory;
       ItemTypePtr headItem;
       unsigned numItems;
    } drinkType;
    
    typedef struct gjc
    {
       CategoryTypePtr headCategory;
       unsigned numCategories;
    } GJCType;
    
    int commandLineArguments(int argc, char *argv[]);
    #endif
    
    
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,375
    Likes Received:
    388
    Trophy Points:
    83
    If I am getting you correctly will not a simple if block solve your problem.
     
  3. Aztec

    Aztec New Member

    Joined:
    May 9, 2006
    Messages:
    90
    Likes Received:
    0
    Trophy Points:
    0
    Just pass your choice 1 or 2 to the function and take decisions based on it using plain old if.

    I hope it will solve your problem. If not, then please explain things more clearly so that people here can try to help you.

    [edit] Didn't really read shabbir's answer. Actually he said the same thing.[/edit]
     
    Last edited: May 19, 2006
  4. musicmancanora4

    musicmancanora4 New Member

    Joined:
    Mar 9, 2006
    Messages:
    42
    Likes Received:
    0
    Trophy Points:
    0
    thanks i got it
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice