This commit is contained in:
Mylloon 2023-01-27 17:49:36 +01:00
parent 4a12db6cfd
commit 99a039898a
Signed by: Anri
GPG key ID: A82D63DFF8D1317F
3 changed files with 18 additions and 11 deletions

View file

@ -1,8 +1,6 @@
#ifndef MYSOK_H
#define MYSOK_H
#include <cstdio>
#include <cstdlib>
#include <string.h>
#include <string>
#define NBL 20
@ -29,7 +27,7 @@ enum board_str {
END_OF_LINE = 'a'
};
const std::string move_str[] = {"Up", "Down", "Left", "Right", "Wait"};
// const std::string move_str[] = {"Up", "Down", "Left", "Right", "Wait"};
struct sok_board_t {
int board[NBL][NBC];

View file

@ -1,29 +1,38 @@
#include "../includes/mysok.h"
sok_board_t::sok_board_t() {
for (int i = 0; i < NBL; i++)
for (int j = 0; j < NBC; j++)
for (int i = 0; i < NBL; i++) {
for (int j = 0; j < NBC; j++) {
board[i][j] = FREE;
}
}
}
void sok_board_t::print_board() {
for (int i = 0; i < board_nbl; i++) {
for (int j = 0; j < NBC; j++) {
if (board[i][j] == END_OF_LINE)
if (board[i][j] == END_OF_LINE) {
break;
}
printf("%c", board[i][j]);
}
printf("\n");
}
}
void sok_board_t::load(char *_file) {
FILE *fp = fopen(_file, "r");
char *line = NULL;
size_t len = 0;
ssize_t nread;
if (fp == NULL) {
perror("fopen");
exit(EXIT_FAILURE);
}
board_nbl = 0;
while ((nread = getline(&line, &len, fp)) != -1) {
if ((static_cast<int>(nread)) > 0) {
@ -83,6 +92,7 @@ void sok_board_t::load(char *_file) {
}
}
}
free(line);
fclose(fp);
}

View file

@ -1,16 +1,15 @@
#include "../includes/mysok.h"
#include <cstdio>
#include <cstdlib>
#include <string.h>
#include <string>
int main(int _ac, char **_av) {
if (_ac != 2) {
printf("usage: %s SOK_FILE\n", _av[0]);
return 0;
}
sok_board_t S;
S.load(_av[1]);
S.print_board();
return 0;
}