Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   printing summay linked list (http://www.go4expert.com/forums/printing-summay-linked-list-t809/)

musicmancanora4 18May2006 20:57

printing summay linked list
 
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


shabbir 18May2006 22:26

Re: printing summay linked list
 
Quote:

Originally Posted by musicmancanora4
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.

If I am getting you correctly will not a simple if block solve your problem.

Aztec 19May2006 05:43

Re: printing summay linked list
 
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]

musicmancanora4 20May2006 08:05

Re: printing summay linked list
 
thanks i got it


All times are GMT +5.5. The time now is 09:54.