Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.07 KB | None | 0 0
  1. //1)lathos me ti malloc,de diavazo sosta onoma kai typo
  2. //2)ελεγχος για αθροισμα χρηστών(πρεπει να ειναι τουλαχιστον elegxos gia athroisma xriston(prepei na einai toylaxiston 1)
  3. //3)olo to 3
  4. //4)check gia 26 grammata
  5. //5)apodesmeusi name kai type
  6. //6)den afinoyme tipota ellinika
  7. //7)backslash n stylish changes
  8.  
  9. #include <stdio.h>
  10. #include <string.h>
  11. #include <stdlib.h>
  12. main()
  13. {
  14. //----------------arxikes diastaseis tamplo -----------------
  15. int dimensions=10,yes,no,flag=1,max,length,*type,users=0, user, computer;
  16. char yesno[4],*nam,**name,typ[9];
  17. int i,players,j;
  18. //----------------epalitheusi gia to an thelei o xristis na paiksei me tis prokathorismens diastaseis------
  19. do
  20. {
  21. printf("Do you want to play by defaut dimensions(10X10)?(yes/no)");
  22. scanf("%s", yesno);
  23. yes=strcmp(yesno,"yes");
  24. no=strcmp(yesno,"no");
  25. if ((yes==0)||(no==0))
  26. {
  27. flag=0;
  28. }
  29. if (flag==1)
  30. {
  31. printf("\n Wrong input.Please choose between default dimensions(yes) and custom dimensions(no)");
  32. }
  33. }while (flag!=0);
  34. //---------------epalitheusi gia to oti oi custom diastaseis tha einai megaliteris i ises tou 5------
  35. if (no==0)
  36. {
  37. do
  38. {
  39. printf("\nChoose your own dimensions");
  40. scanf("%d", &dimensions);
  41. if (dimensions<5)
  42. {
  43. printf("\nWrong input.Please choose a number >=5");
  44. }
  45. }while(dimensions<5);
  46. }
  47. //--------------------paixtes-------------------------
  48. //--------------------arithmos paixton-----------------
  49. do
  50. {
  51. printf("\nChoose the number of players (2 or 4)");
  52. scanf("%d",&players);
  53. if (!((players==2)||(players==4)))
  54. {
  55. printf("\nWrong input.Please choose between 2 or 4");
  56. }
  57. }while(!((players==2)||(players==4)));
  58. //-------------------onoma kai typos paixton-----------
  59. nam=(char*)malloc(players*101);
  60. for (i=0;i<players;i++)
  61. {
  62. nam[i]='\0';
  63. }
  64. printf("\n Enter the name and the type(user or computer) of each player.Keep in mind that there should be at least one user");
  65. type=(int*)malloc(players);
  66. for (i=0;i<players;i++)
  67. {
  68. type[i]=1;
  69. }
  70. for (i=0;i<players;i++)
  71. {
  72. printf("\nEnter the name of player number %d ",i+1);
  73. scanf("%s",&nam[i*101]);
  74. printf("\n Enter the type of player number %d ",i+1);
  75. flag=1;
  76. do
  77. {
  78. scanf("%s", typ);
  79. user=strcmp(typ,"user");
  80. computer=strcmp(typ,"computer");
  81. if ((user==0)||(computer==0))
  82. {
  83. flag=0;
  84. }
  85. if (flag==1)
  86. {
  87. printf("\n Wrong input.Please choose one of your options (user,computer)");
  88. }
  89. }while (flag!=0);
  90. if (user==0)
  91. {
  92. users++;
  93. type[i]=0;
  94. }
  95. }
  96. if (users==0)
  97. {
  98. do
  99. {
  100. printf("There must be at least on user.Please re-enter the type of each player,making sure that there is one user!");
  101. flag=1;
  102. for (i=0;i<players;i++)
  103. {
  104. printf("\n Enter the type of player number %d ",i+1);
  105. do
  106. {
  107.  
  108. scanf("%s", typ);
  109. user=strcmp(typ,"user");
  110. computer=strcmp(typ,"computer");
  111. if ((user==0)||(computer==0))
  112. {
  113. flag=0;
  114. }
  115. if (flag==1)
  116. {
  117. printf("\n Wrong input.Please choose one of your options (user,computer)");
  118. }
  119. }while (flag!=0);
  120.  
  121. }
  122. }while(users==0);
  123. }
  124. max=0;
  125. i=0;
  126. while((nam[i]!='\0')&&(i<101))
  127. {
  128. max++;
  129. i++;
  130. }
  131. length=0;
  132. for (i=101;i<(players*101);i=i+101)
  133. {
  134. while(nam[i]!='\0')
  135. {
  136. length++;
  137. i++;
  138. }
  139. if (length>max)
  140. {
  141. max=length;
  142. }
  143. i=i-length;
  144. length=0;
  145. }
  146. max=max+1;
  147. name=(char**)malloc(players*sizeof(char*));
  148. for (i=0;i<players;i++)
  149. {
  150. name[i]=(char*)malloc(max*sizeof(char));
  151. }
  152. for (i=0;i<players;i++)
  153. {
  154. for (j=0;j<max;j++)
  155. {
  156. name[i][j]=nam[j+(i*101)];
  157. }
  158. }
  159. for (i=0;i<players;i++)
  160. {
  161. j=0;
  162. printf("\nThe player with the name ");
  163. while((name[i][j]!='\0')&&(j<max))
  164. {
  165. printf("%c",name[i][j]);
  166. j++;
  167. }
  168. printf(" is a ");
  169. if (type[i]==0)
  170. {
  171. printf("user");
  172. }
  173. if (type[i]==1)
  174. {
  175. printf("computer");
  176. }
  177. printf("\n");
  178. }
  179. free(name);
  180. free(nam);
  181. free(type);
  182. return 0;
  183. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement