> ~ Online tutorial


Arrays of Strings
In the previous chapter we progressed from one dimensional arrays to two dimensional arrays, or arrays of arrays! The same thing works well for strings which are declared static. Programs can take advantage of C's easy assignment facilities to let the compiler count the size of the string arrays and define arrays of messages. For example here is a program which prints out a menu for an application program:
/*********************************************************/
/*                                                       */
/* MENU : program which prints out a menu                */
/*                                                       */
/*********************************************************/

main ()

{ int str_number;

for (str_number = 0; str_number < 13; str_number++)
   {
   printf ("%s",menutext(str_number));
   }
}

/*********************************************************/

char *menutext(n)           /* return n-th string ptr */

int n;

{
  static char *t[] =
   {
   "  -------------------------------------- \n",
   " |            ++ MENU ++                |\n",
   " |           ~~~~~~~~~~~~               |\n",
   " |     (1) Edit Defaults                |\n",
   " |     (2) Print Charge Sheet           |\n",
   " |     (3) Print Log Sheet              |\n",
   " |     (4) Bill Calculator              |\n",
   " |     (q) Quit                         |\n",
   " |                                      |\n",
   " |                                      |\n",
   " |     Please Enter Choice              |\n",
   " |                                      |\n",
   "  -------------------------------------- \n"
   };
return (t[n]);
}


Please Give Us Your 1 Minute In Sharing This Post!
Please Give Us Your 1 Minute In Sharing This Post!
SOCIALIZE IT →
FOLLOW US →
SHARE IT →
Powered By: BloggerYard.Com

0 comments: