Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #define MAX_LENGTH 100
- #define ROW_LENGTH
- #define EMPTY_SQUARE -1
- #define NOT_FINISH -2
- #define FINISH_SUCCESS 0
- #define FINISH_FAILURE -3
- #define BOARD_SIZE 9
- #define FILLED 1
- #define FAIL -1
- #define MAX_POSSIBILITIES 8
- typedef struct SquareCord //struct for square cords
- {
- short row;
- short col;
- }Cords;
- typedef struct CordsListNode{ //struct for square cords list nodes
- Cords square;
- struct CordsNode* next;
- }CordsNode;
- typedef struct CordsList //struct for square cords list
- {
- CordsNode* head;
- CordsNode* tail;
- }cordList;
- typedef struct RandomSudokoBoard //Random sudoko board struct
- {
- int N;
- cordList list;
- }rndBoard;
- typedef struct _Array
- {
- short *arr;
- unsigned short size;
- } Array;
- typedef struct _Player //Player struct
- {
- char* playerName;
- int sudokuBoard[9][9];
- Array*** possibilitiesArray;
- }player;
- typedef struct PlayerList //Player list struct
- {
- playerNode* head;
- playerNode* tail;
- }playerList;
- typedef struct PlayerListNode //Player list node struct
- {
- player* Player;
- struct playerNode* next;
- }playerNode;
- typedef struct WinnersList
- {
- playerList winlist;
- }winLst;
- typedef struct ActivePlayerList
- {
- playerList activePlayers;
- }activeList;
- typedef struct ActivePlayerArray
- {
- player** playersArr;
- }activeArr;
- char* getPlayerName(int currPlayer);
- int main(void)
- {
- int playerNum;
- int currPlyr = 0;
- activeList activePlayerList;
- makeEmptyPlayerList(&(activePlayerList.activePlayers));
- printf("Please enter the number of players: ");
- scanf("%d\n", &playerNum);
- while (currPlyr < playerNum)
- {
- }
- }
- void makeEmptyPlayerList(playerList *lst)
- {
- lst->head = NULL;
- lst->tail = NULL;
- }
- void AddToEmptyList(playerList *list, playerNode * cell_to_add)
- {
- list->head = list->tail = cell_to_add;
- }
- playerNode* createNewPlayerListNode(playerNode * next)
- {
- int i, j;
- playerNode* res;
- res = (playerNode*)malloc(sizeof(playerNode));
- res->Player = (player*)malloc(sizeof(player));
- for (i = 0; i < 9; i++)
- for (j = 0; j < 9; j++)
- res->Player->sudokuBoard[i][j] = EMPTY_SQUARE;
- res->next = next;
- return res;
- }
- char* getPlayerName(int currPlayer) //this function recieves input from the user,allocates a string that contains the input entered by the user and then returns the starting address of the string
- {
- char* str; //holds the current string
- char ch; //holds the current character
- int logSize = 0; //holds the logical size
- int phsSize = 1; //holds the physical size
- str = (char*)malloc(phsSize*sizeof(char)); //Allocates an array for 'str'
- if (str == NULL)//if allocation fails the program will shut down
- {
- sprintf(stderr, "Allocation failure! program shutting down...");
- exit(-1);
- }
- str[phsSize] = '\0'; //add's '\0' at the end of the string to mark its end
- printf("Please enter the name of player number %d: ", currPlayer + 1);
- ch = getchar(); //gets a character into 'ch'
- while (ch != '\n')
- {
- if (logSize + 1 == phsSize) //checks if the string's logicalsize+1 (for '\0') reaches the end of the size allocated to it
- {
- phsSize *= 2;
- str = (char*)realloc(str, phsSize *sizeof(char)); //Reallocates 'str',increasing its size
- if (str == NULL) //checks if reallocation failed,if so the program will shut down
- {
- sprintf(stderr, "Allocation failure! program shutting down...");
- exit(-1);
- }
- }
- str[logSize] = ch;
- str[logSize + 1] = '\0';
- logSize++;
- ch = getchar();
- }
- str[logSize + 1] = '\0';
- if (logSize < phsSize)//checks if theres excess positions in 'str' that aren't being used and if so the string will be reallocated
- {
- str = (char*)realloc(str, (logSize + 1)*sizeof(char)); //Reallocates 'str',decreasing its size
- if (str == NULL) //checks if reallocation failed,if so the program will shut down
- {
- sprintf(stderr, "Allocation failure! program shutting down...");
- exit(-1);
- }
- }
- if (logSize>0) //checks the string contains atleast 1 character
- return(str);
- else
- return(NULL);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement