-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.c
94 lines (88 loc) · 2.59 KB
/
ui.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <stdio.h>
#include <string.h>
#include "header.h"
// Flushes Standard Input
void FlushStdin(){
int ch;
while (((ch = getchar()) != '\n') && (ch != EOF));
}
// Prompt for random number generator seed
int seedPrompt(int *seed){
int scanResult;
printf("Enter the seed for random number generation: ");
while (1){
scanResult = scanf("%d", seed);
FlushStdin();
if (scanResult == 1)
break;
printf("Seed must be an integer value, please try again\n");
if (scanResult == EOF){
printEOF();
return EOF;
}
else{
printf("Enter the seed for random number generation: ");
}
}
return 0;
}
// Prompt for maximum letter for the game
int maxLetterPrompt(char *maxLetter){
int scanResult;
printf("Enter the maximum letter for the game (A-Z): ");
while (1){
scanResult = scanf(" %c", maxLetter);
FlushStdin();
if (!(scanResult == EOF || *maxLetter < 'A' || *maxLetter > 'Z' || scanResult == 0))
return 0;
printf("The letter must be an uppercase A-Z, please try again\n");
if (scanResult == EOF){
printEOF();
return EOF;
}
else
printf("Enter the maximum letter for the game (A-Z): ");
}
}
// Prompt for the number of positions for the game
int numPosPrompt(int *numPositions){
int scanResult;
printf("Enter the number of positions for the game (1-8): ");
while (1){
scanResult = scanf("%d", numPositions);
FlushStdin();
if (scanResult == EOF){
printf("The number of positions must be 1-8, please try again\n");
printEOF();
return EOF;
}
if (*numPositions < 1 || *numPositions > 8 || scanResult == 0){
printf("The number of positions must be 1-8, please try again\n");
printf("Enter the number of positions for the game (1-8): ");
}
else
return 0;
}
}
// Prompt for the number of guesses allowed
int numGuessPrompt(int *numGuesses){
int scanResult;
printf("Enter the number of guesses allowed for the game: ");
while (1){
scanResult = scanf("%d", numGuesses);
FlushStdin();
if (!(scanResult == EOF || *numGuesses < 1 || scanResult == 0))
return 0;
printf("The number guesses must be a ");
printf("positive integer, please try again\n");
if (scanResult == EOF){
printEOF();
return EOF;
}
else if (*numGuesses < 1 || scanResult == 0)
printf("Enter the number of guesses allowed for the game: ");
}
}
void printEOF(){
fprintf(stderr, "Unexpected EOF\n");
}