-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser_input.c
More file actions
38 lines (31 loc) · 740 Bytes
/
Copy pathuser_input.c
File metadata and controls
38 lines (31 loc) · 740 Bytes
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
#include <stdio.h>
#include <stdlib.h>
#include <user_input.h>
int guessletter(char *word) {
/*
accepted user unput is only small capital letters
*/
char letter;
int guessed = 0;
/* use system call to make terminal send all keystrokes directly to stdin */
system ("/bin/stty raw");
do
{
//printf("\033[2J"); //clear screen
printf ("\rGuess a letter: \b");
scanf ("%c", &letter);
} while ((letter < 'a') || (letter > 'z'));
system ("/bin/stty cooked");
printf("\nDebug: %c\n", letter);
for (int i = 0; word[i] != '\0'; i++) {
if (word[i] == letter) {
guessed++;
}
}
if (guessed > 0) {
printf ("Debug: guessed %i letters\n", guessed);
} else {
printf ("Debug: NONE guessed\n");
}
return guessed;
}