X-Git-Url: https://jxself.org/git/?p=wumpus.git;a=blobdiff_plain;f=superhack.c;h=eff24c2fb4725f604a7137aac28d97397ff93053;hp=78531685b9dbdb45eae392b6a1f56ef73c34f11b;hb=72846062824713185a0b376b91672b846f641dbc;hpb=150263f9d9a1e078ecbc37fb810fcb1ac02b5382 diff --git a/superhack.c b/superhack.c index 7853168..eff24c2 100644 --- a/superhack.c +++ b/superhack.c @@ -15,12 +15,14 @@ #include #include #include +#include #include static int path[5]; static int j, k, scratchloc, pies; static char inp[BUFSIZ]; /* common input buffer */ +#define NUMBERS "0123456789" #define YOU 0 #define RMS 1 #define STARLET1 2 @@ -37,6 +39,8 @@ static int loc[LOCS]; #define LOSE -1 static int finished; +#define IGNORE(r) do{if(r);}while(0) + static int cave[20][3] = { {1,4,7}, @@ -71,7 +75,7 @@ int getlet(prompt) char *prompt; { (void) printf("%s? ", prompt); - if(fgets(inp, sizeof(inp), stdin)) + if (fgets(inp, sizeof(inp), stdin)) return(tolower(inp[0])); else { fputs("\n",stdout); @@ -105,7 +109,7 @@ PM("Cambridge, Massachusetts. Your mission is to throw a pie in his face.\n"); PM(" If a pie hits the superhack, you win. If it hits you, you lose!\n"); (void) fputs("", stdout); - (void) fgets(inp, sizeof(inp), stdin); + IGNORE(fgets(inp, sizeof(inp), stdin)); (void) putchar('\n'); PM("Hazards:"); @@ -223,8 +227,9 @@ void throw() extern void check_shot(), move_superhack(); int j9; - j9 = sscanf(inp + isalpha(inp[0]), "%d %d %d %d %d", + j9 = sscanf(inp + strcspn(inp, NUMBERS), "%d %d %d %d %d", &path[0], &path[1], &path[2], &path[3], &path[4]); + if (j9 < 1) { PM("Sorry, I didn't see any room numbers after your throw command."); @@ -309,7 +314,7 @@ void move_superhack() void move() { - if (sscanf(inp + isalpha(inp[0]), "%d", &scratchloc) < 1) + if (sscanf(inp + strcspn(inp, NUMBERS), "%d", &scratchloc) < 1) { PM("Sorry, I didn't see a room number after your `m' command."); return;