Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //1)lathos me ti malloc,de diavazo sosta onoma kai typo
- //2)ελεγχος για αθροισμα χρηστών(πρεπει να ειναι τουλαχιστον elegxos gia athroisma xriston(prepei na einai toylaxiston 1)
- //3)olo to 3
- //4)check gia 26 grammata
- //5)apodesmeusi name kai type
- //6)den afinoyme tipota ellinika
- //7)backslash n stylish changes
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- main()
- {
- //----------------arxikes diastaseis tamplo -----------------
- int dimensions=10,yes,no,flag=1,max,length,*type,users=0, user, computer;
- char yesno[4],*nam,**name,typ[9];
- int i,players,j;
- //----------------epalitheusi gia to an thelei o xristis na paiksei me tis prokathorismens diastaseis------
- do
- {
- printf("Do you want to play by defaut dimensions(10X10)?(yes/no)");
- scanf("%s", yesno);
- yes=strcmp(yesno,"yes");
- no=strcmp(yesno,"no");
- if ((yes==0)||(no==0))
- {
- flag=0;
- }
- if (flag==1)
- {
- printf("\n Wrong input.Please choose between default dimensions(yes) and custom dimensions(no)");
- }
- }while (flag!=0);
- //---------------epalitheusi gia to oti oi custom diastaseis tha einai megaliteris i ises tou 5------
- if (no==0)
- {
- do
- {
- printf("\nChoose your own dimensions");
- scanf("%d", &dimensions);
- if (dimensions<5)
- {
- printf("\nWrong input.Please choose a number >=5");
- }
- }while(dimensions<5);
- }
- //--------------------paixtes-------------------------
- //--------------------arithmos paixton-----------------
- do
- {
- printf("\nChoose the number of players (2 or 4)");
- scanf("%d",&players);
- if (!((players==2)||(players==4)))
- {
- printf("\nWrong input.Please choose between 2 or 4");
- }
- }while(!((players==2)||(players==4)));
- //-------------------onoma kai typos paixton-----------
- nam=(char*)malloc(players*101);
- for (i=0;i<players;i++)
- {
- nam[i]='\0';
- }
- 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");
- type=(int*)malloc(players);
- for (i=0;i<players;i++)
- {
- type[i]=1;
- }
- for (i=0;i<players;i++)
- {
- printf("\nEnter the name of player number %d ",i+1);
- scanf("%s",&nam[i*101]);
- printf("\n Enter the type of player number %d ",i+1);
- flag=1;
- do
- {
- scanf("%s", typ);
- user=strcmp(typ,"user");
- computer=strcmp(typ,"computer");
- if ((user==0)||(computer==0))
- {
- flag=0;
- }
- if (flag==1)
- {
- printf("\n Wrong input.Please choose one of your options (user,computer)");
- }
- }while (flag!=0);
- if (user==0)
- {
- users++;
- type[i]=0;
- }
- }
- if (users==0)
- {
- do
- {
- printf("There must be at least on user.Please re-enter the type of each player,making sure that there is one user!");
- flag=1;
- for (i=0;i<players;i++)
- {
- printf("\n Enter the type of player number %d ",i+1);
- do
- {
- scanf("%s", typ);
- user=strcmp(typ,"user");
- computer=strcmp(typ,"computer");
- if ((user==0)||(computer==0))
- {
- flag=0;
- }
- if (flag==1)
- {
- printf("\n Wrong input.Please choose one of your options (user,computer)");
- }
- }while (flag!=0);
- }
- }while(users==0);
- }
- max=0;
- i=0;
- while((nam[i]!='\0')&&(i<101))
- {
- max++;
- i++;
- }
- length=0;
- for (i=101;i<(players*101);i=i+101)
- {
- while(nam[i]!='\0')
- {
- length++;
- i++;
- }
- if (length>max)
- {
- max=length;
- }
- i=i-length;
- length=0;
- }
- max=max+1;
- name=(char**)malloc(players*sizeof(char*));
- for (i=0;i<players;i++)
- {
- name[i]=(char*)malloc(max*sizeof(char));
- }
- for (i=0;i<players;i++)
- {
- for (j=0;j<max;j++)
- {
- name[i][j]=nam[j+(i*101)];
- }
- }
- for (i=0;i<players;i++)
- {
- j=0;
- printf("\nThe player with the name ");
- while((name[i][j]!='\0')&&(j<max))
- {
- printf("%c",name[i][j]);
- j++;
- }
- printf(" is a ");
- if (type[i]==0)
- {
- printf("user");
- }
- if (type[i]==1)
- {
- printf("computer");
- }
- printf("\n");
- }
- free(name);
- free(nam);
- free(type);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement