Advertisement
Kenthris

Untitled

Apr 27th, 2017
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.91 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, 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. flag=1;
  99. do
  100. {
  101. printf("There must be at least on user.Please re-enter the type of each player,making sure that there is one user!");
  102. do
  103. {
  104. scanf("%s", typ);
  105. user=strcmp(typ,"user");
  106. computer=strcmp(typ,"computer");
  107. if ((user==0)||(computer==0))
  108. {
  109. flag=0;
  110. }
  111. if (flag==1)
  112. {
  113. printf("\n Wrong input.Please choose one of your options (user,computer)");
  114. }
  115. }while (flag!=0);
  116.  
  117. }while(users==0);
  118. }
  119. max=0;
  120. i=0;
  121. while((nam[i]!='\0')&&(i<101))
  122. {
  123. max++;
  124. i++;
  125. }
  126. length=0;
  127. for (i=101;i<(players*101);i=i+101)
  128. {
  129. while(nam[i]!='\0')
  130. {
  131. length++;
  132. i++;
  133. }
  134. if (length>max)
  135. {
  136. max=length;
  137. }
  138. i=i-length;
  139. length=0;
  140. }
  141. max=max+1;
  142. name=(char**)malloc(players*sizeof(char*));
  143. for (i=0;i<players;i++)
  144. {
  145. name[i]=(char*)malloc(max*sizeof(char));
  146. }
  147. for (i=0;i<players;i++)
  148. {
  149. for (j=0;j<max;j++)
  150. {
  151. name[i][j]=nam[j+(i*101)];
  152. }
  153. }
  154. for (i=0;i<players;i++)
  155. {
  156. j=0;
  157. while((name[i][j]!='\0')&&(j<max))
  158. {
  159. printf("\nThe player with the name ");
  160. printf("%c",name[i][j]);
  161. printf("is a ");
  162. if (type[i]==0)
  163. {
  164. printf("%c",user);
  165. }
  166. if (type[i]==1)
  167. {
  168. printf("%c",computer);
  169. }
  170. j++;
  171. }
  172. printf("\n");
  173. }
  174. free(name);
  175. free(nam);
  176. free(type);
  177. return 0;
  178. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement