Guest User

Untitled

a guest
Feb 25th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.92 KB | None | 0 0
  1. [1]Input //Allow user to input integers individually in the array.
  2. [2]Delete //Delete a certain integer from the array.
  3. [3]Destroy //Remove all values from the array
  4.  
  5. #include <stdio.h>
  6. #include <conio.h>
  7. #include <string.h>
  8. #include <stdlib.h>
  9. #include <ctype.h>
  10. #include <windows.h>
  11.  
  12. int menu();
  13. int MenuNavigation(int rPosition,int nPosition);
  14. int opt1();
  15. int opt2();
  16. int opt3();
  17.  
  18. int main()
  19. {
  20. int x;
  21.  
  22. for(;;)
  23. {
  24. x = menu();
  25. if(x == 1)
  26. {
  27. return 0;
  28. }
  29. }
  30.  
  31. getch();
  32. return 0;
  33. }
  34. int menu()
  35. {
  36. system("cls");
  37. int position = 1;
  38. int kPress = 0;
  39.  
  40. while(kPress != 13)
  41. {
  42. system("cls");
  43.  
  44. printf("n");
  45. MenuNavigation(1,position); printf(" INPUT ARRAYn");
  46. MenuNavigation(2,position); printf(" DELETE ARRAYn");
  47. MenuNavigation(3,position); printf(" DESTROY ALL ARRAYn");
  48. MenuNavigation(4,position); printf(" QUITn");
  49. printf("nnUse arrow keys to navigate the Menu and Press Enter key to Enter");
  50.  
  51. kPress = getch();
  52.  
  53.  
  54. if(kPress == 80 && position != 4)
  55. {
  56. position++;
  57. }
  58. else if(kPress == 72 && position != 1)
  59. {
  60. position--;
  61. }
  62. else
  63. {
  64. position = position;
  65. }
  66. }
  67. if(position == 1)
  68. {
  69. opt1();
  70. }
  71. else if(position == 2)
  72. {
  73. opt2();
  74. }
  75. else if(position == 3)
  76. {
  77. opt3();
  78. }
  79. else if(position == 4)
  80. {
  81. return 1;
  82. }
  83. /*switch(position)
  84. {
  85. case 1:
  86. opt1();
  87. menu();
  88. break;
  89. case 2:
  90. opt2();
  91. break;
  92. case 3:
  93. opt3();
  94. break;
  95. case 4:
  96. printf("nnnEXITTING PROGRAM PRESS ANY KEY TO CONTINUE...");
  97. getch();
  98. return 0;
  99. }*/
  100. }
  101. int MenuNavigation(int rPosition,int nPosition)
  102. {
  103. if(rPosition == nPosition)
  104. {
  105. printf("[X]");
  106. }
  107. else
  108. {
  109. printf(" ");
  110. }
  111. }
  112. int opt1()
  113. {
  114. system("cls");
  115.  
  116. int arr[20];
  117.  
  118. printf("INPUT ARRAYn");
  119. printf(">>");
  120. scanf("%d", &arr);
  121. printf("nn");
  122.  
  123. for(int l=0;l<1;l++)
  124. {
  125. printf("nData[%d] = %d",l,arr[l]);
  126. }
  127.  
  128. printf("nnArray STORED! Returning back to main menu...");
  129. getch();
  130.  
  131. return arr[20];
  132. }
  133. int opt2()
  134. {
  135. int pos,i;
  136. int *arr;
  137. system("cls");
  138. printf("DELETE ARRAYnn");
  139. printf("Enter the element position of the array to deleten");
  140. printf(">>");
  141. scanf("%d", &pos);
  142. if(pos==20+1 || pos<0)
  143. {
  144. printf("Invalid position! Please enter position between 1 to 20");
  145. }
  146. else
  147. {
  148. for(i=pos-1; i<20-1; i++)
  149. {
  150. arr[i] = arr[i + 1];
  151. }
  152. }
  153. printf("nElements of array after delete are : ");
  154. for(i=0; i<20; i++)
  155. {
  156. printf("%dt", arr[i]);
  157. }
  158.  
  159. }
  160. int opt3()
  161. {
  162. //int *arr;
  163. //arr = opt1();
  164. //printf("%d",*arr);
  165. }
Add Comment
Please, Sign In to add comment