/* --------------------------------------------------------------------- ** Figure 13.27: Magic memo maker. ** Figure 13.29: Composing and printing the memo. ** --------------------------------------------------------------------- */ #include "tools.h" void compose( string name, string re, string event ); /* Modifies name. */ #define N 4 /* Number of memo menu choices */ const string menu[N] = {"P Promote", "T Trip", "F Fire", "Q Done"}; #define BOSS "Leland Power" void main( void ) { char memo; /* Menu choice. */ string re, event; /* Subject and main text of memo. */ char name[52]; /* Employee's complete name. */ puts( "\n Magic Memo Maker" ); for(;;) { memo = toupper( menu_c( " Next memo:", N, menu )); if (memo == 'Q') break; /* Leave for loop and end program. */ switch (memo) { case 'P': re = "Promotion"; event = "You are being promoted to assistant manager."; break; case 'T': re = "Trip"; event = "You are tops this year " "and have won a trip to Hawaii."; break; case 'F': re = "Downsizing"; event = "You're fired. \n " "Pick up your final paycheck from personnel."; break; default: puts( "Illegal menu choice" ); continue; } printf( " Enter name: " ); scanf( " %51[^\n]", name ); compose( name, re, event ); } bye(); } /* --------------------------------------------------------------------- */ void /* Side effect: function modifies first argument, name. */ compose( string name, string re, string event ) { string extra, last; /* Pointers used for parsing name. */ printf( "\n\n To: %s\n", name ); printf( " From: The Big Boss\n" ); printf( " Re: %s\n\n", re ); /* Find end and beginning of the last name. */ extra = strchr( name, ',' ); if (extra != NULL) *extra = '\0'; /* mark end of last name */ last = strrchr( name, ' ' ); if (last == NULL) last = name; else ++last; printf( " Dear M. %s:\n %s\n\n -- %s\n\n", last, event, BOSS ); }