diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..55e594c --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +remove +04_basic_struct diff --git a/01_git/scissors.c b/01_git/scissors.c index 66e6853..b9cbd23 100644 --- a/01_git/scissors.c +++ b/01_git/scissors.c @@ -1,47 +1,51 @@ #include #include -#include +#include -const char arr[3] = {'r', 'p', 's'}; +#define ROCK 'r' +#define PAPER 'p' +#define SCISSORS 's' + +const char arr[] = {ROCK, PAPER, SCISSORS}; -int machine_rand(void) { - srand(time(0)); - int random = rand() % 3; - return random; -} int start_game(char input_user, char *machine_choice_c){ - int machine_choice_int = machine_rand(); + srand(time(0)); + int machine_choice_int = rand() % 3; *machine_choice_c = arr[machine_choice_int]; int result; if(input_user == arr[machine_choice_int]) { result = -1; } - else if (input_user == 'r' && arr[machine_choice_int] == 's') + else if (input_user == ROCK && arr[machine_choice_int] == SCISSORS) { result = 1; } - else if (arr[machine_choice_int] == 'r' && input_user == 's') + else if (arr[machine_choice_int] == ROCK && input_user == SCISSORS) { result = 0; } - else if (input_user == 'p' && arr[machine_choice_int] == 'r') + else if (input_user == PAPER && arr[machine_choice_int] == ROCK) { result = 1; } - else if (arr[machine_choice_int] == 'p' && input_user == 'r') + else if (arr[machine_choice_int] == PAPER && input_user == ROCK) { result = 0; } - else if (input_user == 's' && arr[machine_choice_int] == 'p') + else if (input_user == SCISSORS && arr[machine_choice_int] == PAPER) { result = 1; } - else if (arr[machine_choice_int] == 's' && input_user == 'p') + else if (arr[machine_choice_int] == SCISSORS && input_user == PAPER) { result = 0; } + else + { + result = -2; + } return result; } @@ -61,8 +65,12 @@ int main () { { printf("\nYou chose %c and I choose %c, HAHAHAH Machine wins ! \n\n", input_from_user, machine_chose); } - else + else if(result == 1) { printf("\nYou chose %c and I choose %c, You win !\n\n", input_from_user, machine_chose); } -} \ No newline at end of file + else + { + printf("\nYour chose :%c: is incorrect\n\n", input_from_user); + } +} diff --git a/03_module/Makefile b/03_module/Makefile index a54e069..2e28035 100644 --- a/03_module/Makefile +++ b/03_module/Makefile @@ -1,8 +1,10 @@ -obj-m += hello.o +KERNELDIR ?= /home/oporoknyi/Desktop/build/buildroot-2021.02.7/output/build/linux-5.10.7 #WARNING relative path -KDIR:= /usr/src/linux-headers-$(shell uname -r) +obj-m := hello.o all: - $(MAKE) -C $(KDIR) M=$(shell pwd) modules + $(MAKE) -C $(KERNELDIR) M=$(PWD) modules + clean: - make -C /lib/modules/$(shell uname -r)/build M=$(shell pwd) clean + $(MAKE) -C $(KERNELDIR) M=$(PWD) clean + diff --git a/03_module/hello.c b/03_module/hello.c index 49d0e6e..ad782ce 100644 --- a/03_module/hello.c +++ b/03_module/hello.c @@ -3,8 +3,8 @@ #include #include -int a = 0; -int b = 0; +static int a = 0; +static int b = 0; module_param(a, int, 0660); module_param(b, int, 0660); @@ -17,11 +17,11 @@ int hello_init(void) void hello_exit(void) { - printk(KERN_WARNING "\na - b = %i\n", (a < b)?(b - a):(a - b)); + printk(KERN_WARNING "\na - b = %i\n", a - b); } MODULE_LICENSE("GPL"); module_init(hello_init); -module_exit(hello_exit); \ No newline at end of file +module_exit(hello_exit);