fork(2) download
  1. #include<stdio.h>
  2. #include<conio.h>
  3. #include<string.h>
  4. #include<stdlib.h>
  5.  
  6. #define MAX_STACK 10
  7.  
  8. struct tumpukan
  9. {
  10. int top;
  11. char data[10][10];
  12. };
  13.  
  14. struct tumpukan tumpuk;
  15.  
  16. void inisialisasi()
  17. {
  18. tumpuk.top = -1;
  19. }
  20.  
  21. void push(char d[10])
  22. {
  23. tumpuk.top++;
  24. strcpy(tumpuk.data[tumpuk.top],d);
  25. }
  26.  
  27. void pop()
  28. {
  29. printf("Data yang diambil adalah : %s \n",tumpuk.data[tumpuk.top]);
  30. tumpuk.top--;
  31. }
  32.  
  33. void tampilkan(i)
  34. {
  35. for (i=tumpuk.top;i>=0;i--)
  36. {
  37. printf("Stack ke -%i adalah : %s \n",i,tumpuk.data[i]);
  38. }
  39. }
  40.  
  41. int isKosong()
  42. {
  43. if (tumpuk.top==-1)
  44. {
  45. return 1;
  46. }
  47. else
  48. return 0;
  49. }
  50.  
  51. int isPenuh()
  52. {
  53. if (tumpuk.top==MAX_STACK-1)
  54. return 1;
  55. else
  56. return 0;
  57. }
  58.  
  59. void search(int i)
  60. {
  61. char tmp[10];
  62.  
  63. while (i<=tumpuk.top)
  64. {
  65. strcpy(tmp,tumpuk.data[i]);
  66. strcpy(tumpuk.data[i],tumpuk.data[i+1]);
  67. strcpy(tumpuk.data[i+1],tmp);
  68.  
  69. i++;
  70. }
  71.  
  72. pop();
  73. }
  74.  
  75. main()
  76. {
  77. int pil,bil;
  78. inisialisasi();
  79. char dt[10];
  80.  
  81. printf("Selamat datang di program Stack \n");
  82.  
  83. printf("1.Push \n");
  84. printf("2.Pop \n");
  85. printf("3.Tampilkan \n");
  86. printf("4.Clear \n");
  87. printf("5.Search And Remove \n");
  88. printf("6.Exit \n");
  89.  
  90.  
  91. do
  92. {
  93. printf("Masukkan Pilihan : ");scanf("%i",&pil);
  94. switch(pil)
  95. {
  96. case 1 : if (isPenuh()!=1)
  97. {
  98. printf("Masukkan Content Stack : ");scanf("%s",&dt);
  99. push(dt);
  100. }
  101. else
  102. {
  103. printf("sudah penuh \n");
  104. }
  105. break;
  106. case 2 : if (isKosong()!=1)
  107. {
  108. pop();
  109. }
  110. else
  111. {
  112. printf("Masih Kosong \n");
  113. }
  114. break;
  115. case 3 : if (isKosong()!=1)
  116. {
  117. tampilkan();
  118. }
  119. else
  120. {
  121. printf("Masih kosong \n");
  122. }
  123. break;
  124. case 4 : if (isKosong()!=1)
  125. {
  126. printf("cari data yang akan dihilangkan : ");scanf("%i",&bil);
  127. search(bil);
  128. }
  129. else
  130. {
  131. printf("Masih Kosong \n");
  132. }
  133. break;
  134. }
  135. }while(pil!=6);
  136.  
  137. return 0;
  138. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.c:2:18: error: conio.h: No such file or directory
prog.c:76: warning: return type defaults to ‘int’
prog.c: In function ‘main’:
prog.c:98: warning: format ‘%s’ expects type ‘char *’, but argument 2 has type ‘char (*)[10]’
prog.c:93: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result
prog.c:98: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result
prog.c:126: warning: ignoring return value of ‘scanf’, declared with attribute warn_unused_result
stdout
Standard output is empty