|  |
Print a Structure
This widget will generate a function to read in or
print out a C/C++ structure. It can handle #defines, substructures, and
enums. Best of all, it prints enums with their assigned names instead of
useless numeric values. Just supply the structure that you want to read
or print. You also need to supply all #defines, substructures, and enums
used by the structure. After you hit "Submit" the function will
be displayed in your browser. Choose "Save As" on the browser
menu to save the function to a C file on disk where you can then compile
it.
Try it with the supplied example. Just hit "Submit"
and save the file as printfood.c then compile and run. Here is the
header file and a sample main function
to use.
cc foodmain.c printfood.c
Browser Requirements: Any
Notes & Tips:
- The structure should compile without errors.
- By default, the generated code prints to a file.
If you want to print to the screen, use stdout as the file pointer supplied
to the function.
- The "fscanf" option will produce
a function to scan in a text file of the format produced by the "fprintf"
option.
| Example input |
Example output |
/* the meal header */
#define MSIZE 25
typedef enum
{SOFTDRINK, JUICE, COFFEE, MILK, ALCOHOL}
DRINK;
typedef struct {
DRINK drink;
char food[MSIZE];
int calories;
} MEAL;
typedef struct {
MEAL breakfast;
MEAL lunch;
MEAL dinner;
int total_calories;
} DAYS_INTAKE;
|
DAYS_INTAKE mary;
mary.breakfast.drink: COFFEE
mary.breakfast.food: TOAST
mary.breakfast.calories: 50
mary.lunch.drink: SOFTDRINK
mary.lunch.food: SANDWICH
mary.lunch.calories: 200
mary.dinner.drink: MILK
mary.dinner.food: STEAK
mary.dinner.calories: 500
mary.total_calories: 750
|
Make your own
|
 |