Skip to content

Commit

Permalink
Fixed Bugs in 01_git/scissors.c 03_module/Makefile 03_module/hello.c.…
Browse files Browse the repository at this point in the history
… Added .gitingnore
  • Loading branch information
opokornyi committed Dec 16, 2021
1 parent ed2a6c3 commit df3806d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 24 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
remove
04_basic_struct
40 changes: 24 additions & 16 deletions 01_git/scissors.c
Original file line number Diff line number Diff line change
@@ -1,47 +1,51 @@
#include <stdio.h>
#include <stdlib.h>
#include<time.h>
#include <time.h>

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;
}
Expand All @@ -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);
}
}
else
{
printf("\nYour chose :%c: is incorrect\n\n", input_from_user);
}
}
10 changes: 6 additions & 4 deletions 03_module/Makefile
Original file line number Diff line number Diff line change
@@ -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

8 changes: 4 additions & 4 deletions 03_module/hello.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
#include <linux/init.h>
#include <linux/kernel.h>

int a = 0;
int b = 0;
static int a = 0;
static int b = 0;

module_param(a, int, 0660);
module_param(b, int, 0660);
Expand All @@ -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);
module_exit(hello_exit);

0 comments on commit df3806d

Please sign in to comment.