Advertisement
dmilicev

Blanko Meny with char v1.c

Sep 22nd, 2019
326
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 7.97 KB | None | 0 0
  1. /*
  2.  
  3.     Blanko Meny with char v1.c
  4.  
  5. Example for meny.
  6.  
  7. Can be used to get Ascii codes for keyboard keys.
  8.  
  9. with char and getch () respectively getche () and getchar () respectively
  10.  
  11. getch () reads a character from the keyboard and does not display it on the screen
  12. getche () reads a character from the keyboard and displays it on the screen
  13. Both are declared in conio.h and are not standard functions.
  14.  
  15. getch () reads a character from the keyboard and does not display it on the screen.
  16. After the character must be pressed enter.
  17. It is declared in stdio.h and is a standard feature.
  18.  
  19. http://www.c-lang.thiyagaraaj.com/archive/c-blog/use-of-getch-getche-and-getchar-in-c
  20. http://programmingclangauge.weebly.com/getchgetchegets-function.html
  21.  
  22. https://www.daniweb.com/programming/software-development/threads/37195/difference-betn-getch-getche-getchar-functions
  23.  
  24. getchar
  25. This is a standard function that gets a character from the stdin.
  26.  
  27. getch
  28. This is a non-standard function that gets a character from the keyboard, does not echo to the screen.
  29.  
  30. getche This is a non-standard function that gets a character from the keyboard, echoes to screen.
  31.  
  32. Use getchar if you want to work on all compilers.
  33. Use getch or getche on a system that supports it when you want keyboard input without pressing [Enter].
  34.  
  35. And note that the return value of all three is int! You need this to properly check for EOF.
  36.  
  37. */
  38.  
  39.  
  40. #include <stdio.h>
  41. #include <conio.h>  // for getch() and getche()
  42.  
  43.  
  44. // function_1,
  45. void function_1(void) {
  46.  
  47.     int i;
  48.  
  49.     printf("\n\n function_1 \n\n");
  50. }
  51.  
  52.  
  53. // function_2,
  54. void function_2(void) {
  55.  
  56.     int i;
  57.  
  58.     printf("\n\n function_2 \n\n");
  59. }
  60.  
  61.  
  62. // function_3,
  63. void function_3(void) {
  64.  
  65.     int i;
  66.  
  67.     printf("\n\n function_3 \n\n");
  68. }
  69.  
  70.  
  71. // function_4,
  72. void function_4(void) {
  73.  
  74.     int i;
  75.  
  76.     printf("\n\n function_4 \n\n");
  77. }
  78.  
  79.  
  80. // function_5,
  81. void function_5(void) {
  82.  
  83.     int i;
  84.  
  85.     printf("\n\n function_5 \n\n");
  86. }
  87.  
  88.  
  89. // function_6,
  90. void function_6(void) {
  91.  
  92.     int i;
  93.  
  94.     printf("\n\n function_6 \n\n");
  95. }
  96.  
  97.  
  98. // function_7,
  99. void function_7(void) {
  100.  
  101.     int i;
  102.  
  103.     printf("\n\n function_7 \n\n");
  104. }
  105.  
  106.  
  107. // function_8,
  108. void function_8(void) {
  109.  
  110.     int i;
  111.  
  112.     printf("\n\n function_8 \n\n");
  113. }
  114.  
  115.  
  116. // function_9,
  117. void function_9(void) {
  118.  
  119.     int i;
  120.  
  121.     printf("\n\n function_9 \n\n");
  122. }
  123.  
  124.  
  125. // choice_1,
  126. void choice_1(void) {
  127.  
  128.     int i;
  129.  
  130.     printf("\n\n Your choice is choice_1 \n\n");
  131.  
  132.     function_1();
  133.  
  134.     system("PAUSE");
  135. }
  136.  
  137.  
  138. // choice_2,
  139. void choice_2(void) {
  140.  
  141.     int i;
  142.  
  143.     printf("\n\n Your choice is choice_2 \n\n");
  144.  
  145.     function_2();
  146.  
  147.     system("PAUSE");
  148. }
  149.  
  150.  
  151. // choice_3,
  152. void choice_3(void) {
  153.  
  154.     int i;
  155.  
  156.     printf("\n\n Your choice is choice_3 \n\n");
  157.  
  158.     function_3();
  159.  
  160.     system("PAUSE");
  161. }
  162.  
  163.  
  164. // choice_4,
  165. void choice_4(void) {
  166.  
  167.     int i;
  168.  
  169.     printf("\n\n Your choice is choice_4 \n\n");
  170.  
  171.     function_4();
  172.  
  173.     system("PAUSE");
  174. }
  175.  
  176.  
  177. // choice_5,
  178. void choice_5(void) {
  179.  
  180.     int i;
  181.  
  182.     printf("\n\n Your choice is choice_5 \n\n");
  183.  
  184.     function_5();
  185.  
  186.     system("PAUSE");
  187. }
  188.  
  189.  
  190. // choice_6,
  191. void choice_6(void) {
  192.  
  193.     int i;
  194.  
  195.     printf("\n\n Your choice is choice_6 \n\n");
  196.  
  197.     function_6();
  198.  
  199.     system("PAUSE");
  200. }
  201.  
  202.  
  203. // choice_7,
  204. void choice_7(void) {
  205.  
  206.     int i;
  207.  
  208.     printf("\n\n Your choice is choice_7 \n\n");
  209.  
  210.     function_7();
  211.  
  212.     system("PAUSE");
  213. }
  214.  
  215.  
  216. // choice_8,
  217. void choice_8(void) {
  218.  
  219.     int i;
  220.  
  221.     printf("\n\n Your choice is choice_8 \n\n");
  222.  
  223.     function_8();
  224.  
  225.     system("PAUSE");
  226. }
  227.  
  228.  
  229. // choice_9,
  230. void choice_9(void) {
  231.  
  232.     int i;
  233.  
  234.     printf("\n\n Your choice is choice_9 \n\n");
  235.  
  236.     function_9();
  237.  
  238.     system("PAUSE");
  239. }
  240.  
  241.  
  242. // Main meny
  243. char meny(void) {
  244.  
  245.     int c_choice;
  246.  
  247.     while( 1 ) {    // an infinite loop that exits with choice 0 or Ecsape
  248.  
  249.         system("CLS");          // clear the screen
  250.  
  251.         printf("\n\n+--------------------------------------------------+\n"
  252.                    "|                                                  |\n"
  253.                    "|          MAIN MENY                               |\n"
  254.                    "|                                                  |\n"
  255.                    "+--------------------------------------------------+\n"
  256.                    "|                                                  |\n"
  257.                    "| 1. choice_1                                      |\n"
  258.                    "|                                                  |\n"
  259.                    "| 2. choice_2                                      |\n"
  260.                    "|                                                  |\n"
  261.                    "| 3. choice_3                                      |\n"
  262.                    "|                                                  |\n"
  263.                    "| 4. choice_4                                      |\n"
  264.                    "|                                                  |\n"
  265.                    "| 5. choice_5                                      |\n"
  266.                    "|                                                  |\n"
  267.                    "| 6. choice_6                                      |\n"
  268.                    "|                                                  |\n"
  269.                    "| 7. choice_7                                      |\n"
  270.                    "|                                                  |\n"
  271.                    "| 8. choice_8                                      |\n"
  272.                    "|                                                  |\n"
  273.                    "| 9. choice_9                                      |\n"
  274.                    "|                                                  |\n"
  275.                    "| 0. end                                           |\n"
  276.                    "|                                                  |\n"
  277.                    "+--------------------------------------------------+\n\n"
  278.                    " \t Your choice is:  "
  279.                    );
  280.  
  281.         switch( c_choice = getche() ) {  // based on the choices we call the appropriate functions
  282.             case '1' :
  283.                     choice_1();  // choice_1
  284.                     break;
  285.             case '2' :
  286.                     choice_2();  // choice_2
  287.                     break;
  288.             case '3' :
  289.                     choice_3();  // choice_3
  290.                     break;
  291.             case '4' :
  292.                     choice_4();  // choice_4
  293.                     break;
  294.             case '5' :
  295.                     choice_5();  // choice_5
  296.                     break;
  297.             case '6' :
  298.                     choice_6();  // choice_6
  299.                     break;
  300.             case '7' :
  301.                     choice_7();  // choice_7
  302.                     break;
  303.             case '8' :
  304.                     choice_8();  // choice_8
  305.                     break;
  306.             case '9' :
  307.                     choice_9();  // choice_9
  308.                     break;
  309.             case '0' :                  // Zero to end work
  310.                     printf(" Pressed key is %c and it's code is %d \n\n", c_choice , c_choice);
  311.                     return(c_choice);
  312.                     break;
  313.             case 27  :                  // ESC to end work
  314.                     printf(" Pressed key is Escape and it's code is %d \n\n", c_choice );
  315.                     return(c_choice);
  316.                     break;
  317.             case  0  :                      // if pressed function taster
  318.                     printf(" Pressed is function taster %d", c_choice );
  319.                     c_choice = getche();    // let's empty that 0
  320.                     printf(" and it's code is %d \n\n", c_choice, c_choice );
  321.                     system("PAUSE");
  322.                     break;
  323.             case 224 :                  // if pressed special function taster
  324.                     printf(" Pressed is function taster %d", c_choice );
  325.                     c_choice = getche(); // let's empty that -32
  326.                     printf(" and it's code is %d \n\n", c_choice, c_choice );
  327.                     system("PAUSE");
  328.                     break;
  329.             default:
  330.                     printf(" Pressed key is %c and it's code is %d \n\n", c_choice , c_choice);
  331.                     if( c_choice < '0' || c_choice > '9' ) {  // if no digit is entered
  332.                         printf("\n\n You have to choose from (0-9) !!! \n\n");
  333.                         system("PAUSE");
  334.                     }
  335.                     break;
  336.         } // switch( c_choice )
  337.     } // while( 1 )
  338.     return(c_choice);
  339. }
  340.  
  341.  
  342.  
  343.  
  344. // Main program
  345. int main(void) {
  346.  
  347.  
  348.     meny();
  349.  
  350.  
  351.     return 0;
  352. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement