diff --git a/.gitignore b/.gitignore new file mode 100644 index 00000000..91d96a38 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +# Object files +*.o + +# Executables +*.exe +*.out + +# Checkpatch.pl +checkpatch.pl diff --git a/autostart.sh b/autostart.sh new file mode 100755 index 00000000..546feea3 --- /dev/null +++ b/autostart.sh @@ -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 \ No newline at end of file diff --git a/autozip.sh b/autozip.sh new file mode 100755 index 00000000..55809e5b --- /dev/null +++ b/autozip.sh @@ -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" + + diff --git a/main.c b/main.c new file mode 100644 index 00000000..b9e37636 --- /dev/null +++ b/main.c @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: GPL-2.0+ +#include +#include +#include + +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); +} diff --git a/task1-simple-program/README.md b/task1-simple-program/README.md new file mode 100644 index 00000000..8b0a402e --- /dev/null +++ b/task1-simple-program/README.md @@ -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 \ No newline at end of file