/* If Else Program */ /* menu for ASCII chart program */ #include #include #include #include #include #include #include #include void inttoasc (); void asctoint (); void clrscrn (); char y, n, Y, N; main () { char menuOpt; menuOpt = 'x'; while (menuOpt != '3') { clrscr (); printf ("\t\t\t MENU - ASCII CHART PROGRAM"); printf ("\n\t\t\t- - - - - - - - - - - - - - -"); printf ("\n\n\n\n\n\n\n\n\t\t"); printf ("1 - Look up character for an ASCII number"); printf ("\n\n\n"); printf ("\t\t2 - Look up the ASCII number of a character"); printf ("\n\n\n\t\t3 - Quit"); printf ("\n\n\n\n\n\n\n\t\tWHAT IS YOUR CHOICE : "); scanf ("\n%c", &menuOpt); if (menuOpt == '1') { inttoasc (); } else if (menuOpt == '2') { asctoint (); } else if (menuOpt == '3') { clrscrn (); } else { printf ("%c", 7); } } clrscrn (); } void asctoint () /* print ASCII number for */ { /* a given charcter */ char smplChr, again; again = 'Y'; while (again == 'Y' || again == 'y') { clrscrn (); printf ("\nWhat char do you want the ASCII value of : "); scanf ("\n%c", &smplChr); printf ("\nThe ASCII value of %c is %d\n", smplChr, smplChr); again = 'x'; while (again != 'Y' && again != 'y' && again != 'N' && again != 'n') { printf ("\nDo you want to look up another (Y/N) : "); scanf ("\n%c", &again); } } } void inttoasc () /* print character for a */ { /* given ASCII number */ int smplInt; char again; again = 'Y'; while (again == 'Y' || again == 'y') { clrscrn (); printf ("\nWhat number do you want the ASCII char of : "); scanf ("%d", &smplInt); if (smplInt < 33 || smplInt > 254) { printf ("\nThe number must be between 33 and 254"); } else { printf ("\nThe ASCII char for %d is %c\n", smplInt, smplInt); } again = 'x'; while (again != 'Y' && again != 'y' && again != 'n') { printf ("\n\nDo you want to look up another (Y/N) : "); scanf ("\n%c", &again); } } } void clrscrn () /* clear the screen */ { int counter = 0; while (counter != 25) { printf ("\n"); counter = counter + 1; delay(10); } }