Advertisement
Guest User

Untitled

a guest
Sep 30th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.70 KB | None | 0 0
  1. #include <stdlib.h>
  2. #include <time.h>
  3. /*
  4. #include <conio.h>
  5. */
  6.  
  7. #define s 13
  8. #define c 28
  9.  
  10. char deck5[3][7] = {
  11. { '0', '0', '0', '0', '0', '0', '0', '0' },
  12. { '0', '*', '*', '*', '*', '*', '*', '0' },
  13. { '0', '0', '0', '0', '0', '0', '0', '0' }
  14. };
  15.  
  16. char map[s][c]=
  17. {
  18. " 0123456789 0123456789 ",
  19. " ---------- ---------- ",
  20. "0| | 0| |",
  21. "1| | 1| |",
  22. "2| | 2| |",
  23. "3| | 3| |",
  24. "4| | 4| |",
  25. "5| | 5| |",
  26. "6| | 6| |",
  27. "7| | 7| |",
  28. "8| | 8| |",
  29. "9| | 9| |",
  30. " ---------- ---------- ",
  31. };
  32.  
  33. void show(char (*pmap)[c])
  34. {
  35. int i,j;
  36.  
  37. for(i=0; i<s; ++i)
  38. {
  39. for(j=0; j<c; ++j)
  40. {
  41. printf("%c",pmap[i][j]);
  42. }
  43. printf("n");
  44. }
  45. }
  46.  
  47. h_ship5(char (*pmap)[c])
  48. {
  49. int i=0,j=0,x=0,y=0,ii=0,jj=0,yes=0;
  50. do//зацикливает проверку правильности расположения корабля
  51. {
  52.  
  53. x=rand()%7+2;
  54. y=rand()%7+2;
  55. yes=0;
  56.  
  57. for(; j<(y+5); j++)
  58. {
  59. if(pmap[x][j]==' ')
  60. {
  61. yes++;
  62.  
  63. }
  64. }
  65. }
  66. while(yes<5);
  67. x--,y--;
  68. i=x,j=y;
  69.  
  70. for(;i<(x+3);i++){
  71. if(jj==7){
  72. ii++;
  73. jj=0;}
  74. for(;j<(y+7);j++){
  75. jj++;
  76. if(pmap[i][j]==' ')
  77. pmap[i][j]=deck5[ii][jj];
  78. }
  79. }
  80.  
  81. return pmap;
  82.  
  83. }
  84.  
  85. int main()
  86. {
  87. srand( (unsigned)time( NULL ) );
  88.  
  89. char*pmap=map;
  90.  
  91. pmap=h_ship5(pmap);
  92. show(pmap);
  93. return 0;
  94. }
  95.  
  96. #define s 13
  97. #define c 28
  98. #define a 3
  99. #define b 8
  100.  
  101. char deck5[a][b] = {
  102. "0000000",
  103. "0*****0",
  104. "0000000",};
  105.  
  106. char map[a][b] = {
  107. "1111111",
  108. "1*****1",
  109. "1111111",};
  110.  
  111. int main(int argc, char** argv) {
  112. int i = 0, j = 0;
  113.  
  114. for (; i < 3; i++) {
  115. for (; j < 7; j++) {
  116. map[i][j] = deck5[i][j];
  117. //if(j==7)deck5[i][j]=''; или map[i][j]=''; или оба варианта вместе не помогают
  118. }
  119. }
  120.  
  121. for (i = 0; i < a; ++i) {
  122. for (j = 0; j < b; ++j) {
  123. printf("%c", map[i][j]);
  124. }
  125. printf("n");
  126. }
  127.  
  128. return (EXIT_SUCCESS);
  129. }
  130.  
  131. Desktoptesttest_fightmain.c||In function 'show':|
  132.  
  133. Desktoptesttest_fightmain.c|41|warning: implicit declaration of function 'printf'|
  134.  
  135. Desktoptesttest_fightmain.c|41|warning: incompatible implicit declaration of built-in function 'printf'|
  136.  
  137. Desktoptesttest_fightmain.c|43|warning: incompatible implicit declaration of built-in function 'printf'|
  138.  
  139. Desktoptesttest_fightmain.c|49|warning: return type defaults to 'int'|
  140.  
  141. Desktoptesttest_fightmain.c||In function 'h_ship5':|
  142.  
  143. Desktoptesttest_fightmain.c|82|warning: return makes integer from pointer without a cast|
  144.  
  145. Desktoptesttest_fightmain.c||In function 'main':|
  146.  
  147. Desktoptesttest_fightmain.c|91|warning: initialization from incompatible pointer type|
  148.  
  149. Desktoptesttest_fightmain.c|93|warning: passing argument 1 of 'h_ship5' from incompatible pointer type|
  150.  
  151. Desktoptesttest_fightmain.c|48|note: expected 'char (*)[28]' but argument is of type 'char *'|
  152.  
  153. Desktoptesttest_fightmain.c|93|warning: assignment makes pointer from integer without a cast|
  154.  
  155. Desktoptesttest_fightmain.c|94|warning: passing argument 1 of 'show' from incompatible pointer type|
  156.  
  157. Desktoptesttest_fightmain.c|33|note: expected 'char (*)[28]' but argument is of type 'char *'|
  158.  
  159. ||=== Build finished: 0 errors, 9 warnings ===|
  160.  
  161. char deck5[3][7] = { "0000000",
  162. "0*****0",
  163. "0000000",
  164. };
  165.  
  166. char deck5[3][7] = {
  167. { '0', '0', '0', '0', '0', '0', '0' },
  168. { '0', '*', '*', '*', '*', '*', '0' },
  169. { '0', '0', '0', '0', '0', '0', '0' }
  170. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement