Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Homework task2: Complete #43

Open
wants to merge 15 commits into
base: Maksym.Khomenko
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Object files
*.o

# Executables
*.exe
*.out

# Checkpatch.pl
checkpatch.pl
38 changes: 38 additions & 0 deletions autostart.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/bin/bash

COUNT=0
# Reset
Color_Off='\033[0m' # Text Reset
# Regular Colors
Black='\033[0;30m' # Black
Red='\033[0;31m' # Red
Green='\033[0;32m' # Green
Yellow='\033[0;33m' # Yellow
Blue='\033[0;34m' # Blue
Purple='\033[0;35m' # Purple
Cyan='\033[0;36m' # Cyan
White='\033[0;97m' # White

while true; do
./main.out
# Check the result and depending on it print greetings
if [ $? -eq 0 ]; then
echo -e "${Green}Good job!${White}"
else
echo -e "${Red}Wish a good luck next time.${White}"
fi

if [ $COUNT -eq 0 ]; then
read -p "$(echo -e $Yellow'Continue? (Y/N) or number of tries '$White)" reply
# Check if reply is not a number
if ! [[ $reply =~ ^[0-9]+$ ]]; then
if [ "$reply" = "N" ] || [ "$reply" = "n" ]; then
break
fi
else
let COUNT=$((reply-1))
fi
else
let COUNT-=1
fi
done
29 changes: 29 additions & 0 deletions autozip.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#!/bin/sh

DIR="/tmp/guesanumber"
DEST="./release"

if [ ! -d "$DIR" ]; then
# If directory dosen't exist create it.
mkdir "$DIR"
fi

# If *.c files exist then copy them all.
if [ -f *.c ]; then
cp *.c "$DIR"
fi
# If *.h files exist then copy them all.
if [ -f *.h ]; then
cp *.h "$DIR"
fi
# Create a gzip archive
tar -zcvf ""$DIR".tar.gz" "$DIR"

if [ ! -d "$DEST" ]; then
# If directory dosen't exist create it.
mkdir "$DEST"
fi
# Copy archive to the ./release
cp ""$DIR".tar.gz" "$DEST"


27 changes: 27 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// SPDX-License-Identifier: GPL-2.0+
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int range_rand(int min, int max)
{
srand(time(NULL));
return (min + rand() % (max - min + 1));
}

int main(void)
{
int x, x_gues, ret_val;

printf("Enter your number in the range from 0 to 9\n");
scanf("%u", &x_gues);
x = range_rand(0, 9);
if (x == x_gues) {
printf("You Win!\n");
ret_val = 0;
} else {
printf("You Lose\nThe lucky number was %d\n", x);
ret_val = -1;
}
return (ret_val);
}
13 changes: 13 additions & 0 deletions task1-simple-program/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Simple c program with commits
The main idea of of this task is to demonstrate your ability to work with git and create correctly formed commit.
So, you have to focus on the rules and principals of working with github, not on code complexity.
## Task
1. Please, write simple game "guess a number". User input some number from 0 to 9. Computer also generates random number from 0 to 9. If values are equal, user will get message “You win”. In other case – “You loose”. main() function should return 0 if you win, and non-zero value otherwise.
2. When you working on code, please divide it on several steps. Each steps will be new commit. There are possible steps:
a. Create simple *.c file with empty main() function
b. Write main functionality
c. Rewrite code, that random number generates in you own defined function.
3. Check coding style with checkpatch.pl
4. Also don't forget to create .gitignore file
5. Create pull request to this repo into you own branch (have to be already exist)
6. Good luck