added input struct

This commit is contained in:
Lorenzo Bianchi 2023-05-14 17:53:38 +02:00
parent fd976b20d8
commit 564de330d1
2 changed files with 19 additions and 9 deletions

View File

@ -1,6 +1,13 @@
#ifndef SERVER_H
#define SERVER_H
void check_input(int argc, char *argv[]);
typedef struct input {
int collums;
int rows;
char player1Token;
char player2token;
} input_t;
input_t check_input(int argc, char *argv[]);
#endif

View File

@ -4,7 +4,7 @@
#include <../inc/server.h>
#include <../inc/errExit.h>
void check_input(int argc, char *argv[]){
input_t check_input(int argc, char *argv[]){
if (argc < 5) {
printf("\033[92m<Help>\033[39m Arguments:\n1) number of collums\n2) number of rows\n3) player one token\n4) player two token\n");
exit(EXIT_SUCCESS);
@ -12,17 +12,20 @@ void check_input(int argc, char *argv[]){
errExitMsg("To many arguments");
}
int collums = atoi(argv[1]);
int rows = atoi(argv[2]);
input_t input = {
.collums = atoi(argv[1]),
.rows = atoi(argv[2]),
.player1Token = argv[3],
.player2token = argv[4]
};
char *player1 = argv[3];
char *player2 = argv[4];
if (collums<5 || rows<5) {
if (input.collums<5 || input.rows<5) {
errExitMsg("To few rows or collums");
}
if (player1 == NULL || player2 == NULL) {
if (input.player1Token == NULL || input.player2token == NULL) {
errExitMsg("Invalid player names");
}
return input;
}