-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.c
60 lines (52 loc) · 1.19 KB
/
test.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
#include <fcntl.h>
#include <sys/ioctl.h>
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#include <stdio.h>
#include <errno.h>
#include "mastermind.h"
int main()
{
int fd, retval = 0;
char mmindNumber[3];
fd = open("/dev/mastermind", 0);
if (fd == -1) {
printf("Device cannot be accessed!\n");
}
printf("1 : REMAINING\n");
printf("2 : END GAME\n");
printf("3 : NEW GAME\n");
printf("Make Your Choice:\n");
int choice;
scanf("%d", &choice);
switch(choice) {
case 1:
retval = ioctl(fd, MMIND_REMAINING);
if(retval == -1){
printf("You should set device\n");
printf("Remaining guesses: %d\n",10);
}else{
printf("Remaining guesses: %d\n",retval);
}
//printf("sonra %s",retval);
break;
case 2:
retval = ioctl(fd, MMIND_ENDGAME);
printf("Game terminated.\n");
break;
case 3:
printf("Mastermind Number:\n");
scanf("%s", mmindNumber);
retval = ioctl(fd, MMIND_NEWGAME, mmindNumber);
printf("retval-new game: %d\n",retval);
break;
default:
printf("Sorry I could not understand you\n");
}
if (retval == -EPERM) {
printf("You need to be root!\n");
}
close(fd);
return 0;
}