Advertisement
dmilicev

Blanko Meny with int v1.c

Sep 22nd, 2019
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.52 KB | None | 0 0
  1. /*
  2.  
  3.     BLANKO meny with int v1.c
  4.  
  5.     There is a problem if you in
  6.  
  7.     scanf("%d",&choice);
  8.  
  9.     enter something else than 0-9. In that case, exit with Ctrl-Break.
  10.  
  11.     This is resolved as follows:
  12.  
  13.     int choice;
  14.     char terminator;
  15.  
  16.     printf("\n Enter a number: ");
  17.  
  18.     // On success, the function scanf() returns the number
  19.     // of items of the argument list successfully read.
  20.     // If scanf didn't read two elements, integer and char, and return 2
  21.     // or if second element terminator isn't enter '\n'
  22.     // then first element isn't integer.
  23.     if( scanf("%d%c", &choice, &terminator) != 2 || terminator != '\n' )
  24.     {
  25.         printf("\n choice = %d is not an integer ! \n");
  26.         return(1);
  27.     }
  28. */
  29.  
  30.  
  31. #include <stdio.h>
  32.  
  33.  
  34. // function_1,
  35. void function_1(void) {
  36.  
  37.     int i;
  38.  
  39.     printf("\n\n function_1 \n\n");
  40. }
  41.  
  42.  
  43. // function_2,
  44. void function_2(void) {
  45.  
  46.     int i;
  47.  
  48.     printf("\n\n function_2 \n\n");
  49. }
  50.  
  51.  
  52. // function_3,
  53. void function_3(void) {
  54.  
  55.     int i;
  56.  
  57.     printf("\n\n function_3 \n\n");
  58. }
  59.  
  60.  
  61. // function_4,
  62. void function_4(void) {
  63.  
  64.     int i;
  65.  
  66.     printf("\n\n function_4 \n\n");
  67. }
  68.  
  69.  
  70. // function_5,
  71. void function_5(void) {
  72.  
  73.     int i;
  74.  
  75.     printf("\n\n function_5 \n\n");
  76. }
  77.  
  78.  
  79. // function_6,
  80. void function_6(void) {
  81.  
  82.     int i;
  83.  
  84.     printf("\n\n function_6 \n\n");
  85. }
  86.  
  87.  
  88. // function_7,
  89. void function_7(void) {
  90.  
  91.     int i;
  92.  
  93.     printf("\n\n function_7 \n\n");
  94. }
  95.  
  96.  
  97. // function_8,
  98. void function_8(void) {
  99.  
  100.     int i;
  101.  
  102.     printf("\n\n function_8 \n\n");
  103. }
  104.  
  105.  
  106. // function_9,
  107. void function_9(void) {
  108.  
  109.     int i;
  110.  
  111.     printf("\n\n function_9 \n\n");
  112. }
  113.  
  114.  
  115. // choice_1,
  116. void choice_1(void) {
  117.  
  118.     int i;
  119.  
  120.     printf("\n\n Your choice is choice_1 \n\n");
  121.  
  122.     function_1();
  123.  
  124.     system("PAUSE");
  125. }
  126.  
  127.  
  128. // choice_2,
  129. void choice_2(void) {
  130.  
  131.     int i;
  132.  
  133.     printf("\n\n Your choice is choice_2 \n\n");
  134.  
  135.     function_2();
  136.  
  137.     system("PAUSE");
  138. }
  139.  
  140.  
  141. // choice_3,
  142. void choice_3(void) {
  143.  
  144.     int i;
  145.  
  146.     printf("\n\n Your choice is choice_3 \n\n");
  147.  
  148.     function_3();
  149.  
  150.     system("PAUSE");
  151. }
  152.  
  153.  
  154. // choice_4,
  155. void choice_4(void) {
  156.  
  157.     int i;
  158.  
  159.     printf("\n\n Your choice is choice_4 \n\n");
  160.  
  161.     function_4();
  162.  
  163.     system("PAUSE");
  164. }
  165.  
  166.  
  167. // choice_5,
  168. void choice_5(void) {
  169.  
  170.     int i;
  171.  
  172.     printf("\n\n Your choice is choice_5 \n\n");
  173.  
  174.     function_5();
  175.  
  176.     system("PAUSE");
  177. }
  178.  
  179.  
  180. // choice_6,
  181. void choice_6(void) {
  182.  
  183.     int i;
  184.  
  185.     printf("\n\n Your choice is choice_6 \n\n");
  186.  
  187.     function_6();
  188.  
  189.     system("PAUSE");
  190. }
  191.  
  192.  
  193. // choice_7,
  194. void choice_7(void) {
  195.  
  196.     int i;
  197.  
  198.     printf("\n\n Your choice is choice_7 \n\n");
  199.  
  200.     function_7();
  201.  
  202.     system("PAUSE");
  203. }
  204.  
  205.  
  206. // choice_8,
  207. void choice_8(void) {
  208.  
  209.     int i;
  210.  
  211.     printf("\n\n Your choice is choice_8 \n\n");
  212.  
  213.     function_8();
  214.  
  215.     system("PAUSE");
  216. }
  217.  
  218.  
  219. // choice_9,
  220. void choice_9(void) {
  221.  
  222.     int i;
  223.  
  224.     printf("\n\n Your choice is choice_9 \n\n");
  225.  
  226.     function_9();
  227.  
  228.     system("PAUSE");
  229. }
  230.  
  231.  
  232. int meny(void)
  233. {
  234.     int choice, end=0;
  235.     char terminator;
  236.  
  237.     while(!end){
  238.  
  239.     system("CLS");      // clear the screen
  240.  
  241.     printf("\n\n+--------------------------------------------------+\n"
  242.                "|                                                  |\n"
  243.                "|          MAIN MENY                               |\n"
  244.                "|                                                  |\n"
  245.                "+--------------------------------------------------+\n"
  246.                "|                                                  |\n"
  247.                "| 1. choice_1                                      |\n"
  248.                "|                                                  |\n"
  249.                "| 2. choice_2                                      |\n"
  250.                "|                                                  |\n"
  251.                "| 3. choice_3                                      |\n"
  252.                "|                                                  |\n"
  253.                "| 4. choice_4                                      |\n"
  254.                "|                                                  |\n"
  255.                "| 5. choice_5                                      |\n"
  256.                "|                                                  |\n"
  257.                "| 6. choice_6                                      |\n"
  258.                "|                                                  |\n"
  259.                "| 7. choice_7                                      |\n"
  260.                "|                                                  |\n"
  261.                "| 8. choice_8                                      |\n"
  262.                "|                                                  |\n"
  263.                "| 9. choice_9                                      |\n"
  264.                "|                                                  |\n"
  265.                "| 0. end                                           |\n"
  266.                "|                                                  |\n"
  267.                "+--------------------------------------------------+\n\n"
  268.                " \t Your choice is:  "
  269.                );
  270.  
  271.         //scanf("%d",&choice);
  272. /*
  273.     There is a problem with function scanf(), if you enter something else than 0-9,
  274.     the program will crash.
  275.     In that case, exit with Ctrl-Break.
  276.  
  277.     This is resolved as follows:
  278. */
  279.         // On success, the function scanf() returns the number
  280.         // of items of the argument list successfully read.
  281.         // If scanf didn't read two elements, integer and char, and return 2
  282.         // or if second element terminator isn't enter '\n'
  283.         // then first element isn't integer.
  284.         if( scanf("%d%c", &choice, &terminator) != 2 || terminator != '\n' )
  285.         {
  286.             printf("\n choice = %d is not an integer ! \n");
  287.             printf("\n You have to choose from (0-9) !!! \n\n");
  288.             return(1);
  289.         }
  290.  
  291.         switch(choice){
  292.             case 1:
  293.                     choice_1();  // choice_1
  294.                     break;
  295.             case 2:
  296.                     choice_2();  // choice_2
  297.                     break;
  298.             case 3:
  299.                     choice_3();  // choice_3
  300.                     break;
  301.             case 4:
  302.                     choice_4();  // choice_4
  303.                     break;
  304.             case 5:
  305.                     choice_5();  // choice_5
  306.                     break;
  307.             case 6:
  308.                     choice_6();  // choice_6
  309.                     break;
  310.             case 7:
  311.                     choice_7();  // choice_7
  312.                     break;
  313.             case 8:
  314.                     choice_8();  // choice_8
  315.                     break;
  316.             case 9:
  317.                     choice_9();  // choice_9
  318.                     break;
  319.             case 0:
  320.                     end = 1;        // exit
  321.                     break;
  322.             default :
  323.                     printf("\n\n \t You have to choose (0-9) ! \n\n");
  324.                     break;
  325.         } // switch(choice)
  326.     } // while(!end)
  327.     return choice;
  328. } // meny()
  329.  
  330.  
  331.  
  332.  
  333. // Main program
  334. int main(void)
  335. {
  336.  
  337.     meny();
  338.  
  339.  
  340.     return 0;
  341. } // Main program
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement