#include #include #include "coordinate.h" #include "input.h" #include "move.h" #define LENGTH 80 Move input_move() { Coord orig, dest; char line[LENGTH], orig_line[3], dest_line[3]; int done = 0; printf("Please, enter your movement: "); while (!done) { fgets(line, LENGTH, stdin); if (strnlen(line, LENGTH) == 6 && line[2] == '-' && line[5] == '\n') { orig_line[0] = line[0]; orig_line[1] = line[1]; orig_line[2] = 0; dest_line[0] = line[3]; dest_line[1] = line[4]; dest_line[2] = 0; printf("Coordinates %s-%s\n", orig_line, dest_line); if (!coord_is_valid(orig_line) || !coord_is_valid(dest_line)) printf("Invalid coordinate, try again: "); else { orig = coord_init(orig_line); dest = coord_init(dest_line); done = 1; } } else printf("Invalid movement. Write something like \"e2-e4\": "); } return move_init(orig, dest); }