From f7098bcf35b095ce98acaee9f969981e6ef9a43e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ra=C3=BAl=20Benencia?= Date: Tue, 31 Mar 2015 15:13:34 -0300 Subject: input coordinates from stdin --- lib/input.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 lib/input.c (limited to 'lib/input.c') diff --git a/lib/input.c b/lib/input.c new file mode 100644 index 0000000..63df8c5 --- /dev/null +++ b/lib/input.c @@ -0,0 +1,38 @@ +#include +#include + +#include "coordinate.h" +#include "input.h" + +#define LENGTH 80 + +static Coord _input_coord() { + char line[LENGTH]; + int done = 0; + + while (!done) { + fgets(line, LENGTH, stdin); + + if (strnlen(line, LENGTH) == 3 && line[2] == '\n') + line[2] = 0; + + if (!coord_is_valid(line)) + printf("Invalid coordinate. Write something like \"e2\": "); + else + done = 1; + } + + return coord_init(line); +} + +Coord input_orig_coord() { + printf("Orig coordinate: "); + + return _input_coord(); +} + +Coord input_dest_coord() { + printf("Dest coordinate: "); + + return _input_coord(); +} -- cgit v1.2.3