Skip to content
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
26 changes: 26 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
dist: focal
sudo: required # используем Virtual Machine (а не Docker container)

language: c

os:
- linux

branches:
only:
- other

compiler:
- gcc

install:
- sudo apt-get install valgrind
- sudo pip3 install cpplint
- sudo apt install cppcheck

script:
- mkdir build
- cd build
- cmake ..
- cmake —build .
- ctest —output-on-failure
15 changes: 15 additions & 0 deletions .vscode/c_cpp_properties.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${default}"
],
"compilerPath": "C:/Program Files/mingw-w64/x86_64-8.1.0-posix-seh-rt_v6-rev0/mingw64/bin/gcc.exe",
"cStandard": "c17",
"cppStandard": "c++17",
"intelliSenseMode": "linux-gcc-x64"
}
],
"version": 4
}
Comment on lines +1 to +15
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Зачем здесь этот файл?

15 changes: 15 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
cmake_minimum_required(VERSION 3.16)

project(test)

set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}-pthread")

set(LIB_SOURCE_FILE function.c)
add_library(server STATIC ${LIB_SOURCE_FILE})

add_compile_options("-lgcov —coverage")

add_executable(main DZ1.c)
target_link_libraries(main server)
43 changes: 43 additions & 0 deletions DZ1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
#include "function.h"

int main() {
srand(time(NULL));
mus_comp *array_mu_co = (mus_comp*)malloc(sizeof(mus_comp));\
if (array_mu_co == NULL)
{
printf("Error associeted with malloc() in main()!");
}
mus_comp element_mu_co;
char strin[MAX_SIZE_STRING];
int number_in_array, size_array = 1, input_count;
FILE *fin = fopen("C:\\Users\\Omar\\Desktop\\Tehnopark_C_Cpp\\Second\\DataBase.txt", "r");
if (fin == NULL)
{
printf("Error! File with data can't open!");
return 0;
}
for (number_in_array = 0;number_in_array < 125;++number_in_array) {
if (fgets(strin, MAX_SIZE_STRING, fin) == NULL)
{
printf("Error with gets()!");
return 0;
}
element_mu_co = create_struct_music_composition(strin, fin);
if (element_mu_co.duration == NULL)
{
return 0;
}
array_mu_co = add_in_array(array_mu_co, &size_array, &number_in_array, element_mu_co);
if (array_mu_co == NULL)
{
return 0;
}
}
scanf("How many tracks do you want to see? %d",&input_count);
if (find_random_music_composition(array_mu_co, number_in_array, input_count) == ERROR)
{
return 0;
}
fclose(fin);
return 0;
}
125 changes: 125 additions & 0 deletions DataBase.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
151 255 Evening Of Siilence
150 251 Town Of Minds
154 248 Fire Of My Beginning
151 257 Dreamy Step
151 252 Beat Game
150 252 Dearest, Hold My Hand
153 246 Babe, You And I
150 241 He Hopes He Can Dance
154 259 I Said He Can Sing
154 253 Life For The World
154 249 Angel Of Subtlety
154 249 Song Of My Song
151 257 Thoughts Of My Love
150 245 Dreamy Games
151 247 Faded Heaven
154 251 I'm Feeling Good
150 244 Babe, I'm In The Mood
151 254 She Said She's Innocent
152 256 He Knows He's In The Mood
150 255 Woman For Love
154 241 All For The World
153 258 Memories Of My Story
152 254 Bridge Of My Memories
153 252 Summer Things
154 244 Best Games
154 255 I'm Lonely Without You
153 246 Darling, Remember The Good
152 247 She Hopes He's Amazing
152 256 She Knows I Can Sing
154 249 New Kind Of The Good Life
152 248 Thoughts Of Dreams
154 247 Home Of My Home
153 246 Interlude Of My Soul
150 248 Welcome Promises
154 254 Walking Things
154 242 Babe, You're Perfect
152 256 I'm Glad I'm Yours
153 240 You Love Me
154 259 He Loves You Can Dance
151 244 Songs Of The Most Beautiful
152 255 Dance For The Past
150 259 Moments Of My Pleasures
151 246 Home Of My Way
154 250 Sweet Beauty
154 245 Dearest Drink
151 252 Dearest, Without You
154 246 Baby, You're My Favorite
152 248 She Thinks I Can Dance
150 244 I Think She's Charming
154 240 Man For An Evening
151 240 Speak Of Solitude
152 244 Suite Of My Soul
151 247 Soul Of My Voice
151 242 Nightlife Paradise
151 256 Morning Beats
152 244 You're A Mystery
153 253 Honey, Let's Be Free
151 246 She Thinks She's In The Mood
150 255 I Think She Got It Going
151 259 Man For An Evening
154 253 Speak Of Solitude
150 255 Suite Of My Soul
152 246 Soul Of My Voice
152 259 Nightlife Paradise
150 249 Morning Beats
153 255 You're A Mystery
152 244 Honey, Let's Be Free
152 258 She Thinks She's In The Mood
151 259 I Think She Got It Going
150 252 End Of Nothing
153 242 Dance For The Road
151 252 Tickle My Power
154 241 Cling To My Life
150 250 Birthday Tomorrow
150 248 First Machine
150 258 Babe, This Love Of Mine
152 246 Babe, I Waited For You
150 247 He Knows I Won't Stop
151 241 I Hope He Likes To Party
150 251 Matter For Me
154 259 Melody For The Night
150 251 Dreams Of My Rhythm
153 240 Five Of My Pleasures
152 241 Strange Drink
151 259 Evening Chances
154 244 Honey, Until I Met You
151 245 Dearest, Come Back
151 244 I Hope She Wrote
152 247 He Hopes I'm In Love
154 244 Baal
152 240 No Window
150 256 Kadasarva
152 253 Trylon And Perisphere
152 247 The Misted Muppet
151 250 Photos Of Ghosts
153 256 Digital Talk
153 244 New Age Surf
150 242 Logic Bomb
150 258 Sonic Algebra
151 248 Man With No Name
154 255 Axis Flip
153 258 Hypersonic
151 240 Dramatic Combo
151 257 Overend Show
152 245 Infected Mushroom
152 244 Cream
154 251 Benza
154 250 Duck And Cover
150 255 Troll Scientists
154 257 Phone The Lab
152 257 Ananda Shake
151 251 Banana Banji
150 253 Team 18 9+9
150 240 Analog Pussy
150 241 Spooky Loops
152 249 Generator Man
150 257 Sabretooth
153 252 Smooth Hound
154 248 Bio-Tonic
153 248 Mexicosed Brains
151 244 Toï Doï Fusion
150 258 Froide
154 248 Igor Swamp
154 252 Stiff Manure
152 243 Sattel Battle
84 changes: 84 additions & 0 deletions function.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#include "function.h"

mus_comp *add_in_array(mus_comp *array_mu_co,int *SizeArray, int *number_in_array, mus_comp element_mu_co)
{
if ((array_mu_co == NULL) || (SizeArray == NULL))
{
printf("Error associated with pointers in function add_in_array()!");
return NULL;
}
if (*number_in_array + 1 == *SizeArray)
{
(*SizeArray) *= 2;
mus_comp *old_ptrarray_mu_co = array_mu_co;
array_mu_co = (mus_comp *) realloc(old_ptrarray_mu_co,(*SizeArray)*sizeof(mus_comp));
if (array_mu_co == NULL)
{
printf("Error associated with Realloc() in function add_in_array()!");
}
}

array_mu_co[*number_in_array] = element_mu_co;
return array_mu_co;
}

int output_info(mus_comp *array_mu_co, int number_in_array)
{
if (array_mu_co == NULL)
{
printf("Error associated with pointers in function output_info()!");
return ERROR;
}
int i = 0;
while (i != number_in_array)
{
mus_comp element_mu_co;
element_mu_co = array_mu_co[i];
printf("\n INDEX[%d]\n Bit: %d \n Duration: %d \n Name: %s\n",i, element_mu_co.bit, element_mu_co.duration, element_mu_co.name);
i++;
}
}

int find_random_music_composition(mus_comp *array_mu_co, int number_in_array, int coun_element)
{
if (array_mu_co == NULL)
{
printf("Error associated with pointers in function output_info()!");
return ERROR;
}
int rand_bit = rand()%5 + 150;
int rand_duration=rand()%20 + 240;
int out_count = 1;
int index = 0;
printf(" Search for a track with parameters such as:\n Rhythm-> %d +-1 bit/min \n Duration -> %d +-5 second \n",rand_bit, rand_duration);
while ((out_count != coun_element+1) && (index < number_in_array))
{
if ((abs(array_mu_co[index].bit - rand_bit) <= 1) && (abs(array_mu_co[index].duration - rand_duration) <= 5))
{
mus_comp element_mu_co = array_mu_co[index];
printf("\n INDEX[%d]\n Bit: %d \n Duration: %d \n Name: %s\n",out_count, element_mu_co.bit, element_mu_co.duration, element_mu_co.name);
++out_count;
}
index++;
}
if (out_count != coun_element + 1) printf("There are no more music tracks with such parameters.");
}

mus_comp create_struct_music_composition(char *strin, FILE *fin)
{
if (strin == NULL)
{
printf("Error associated with pointers in function output_info()!");
mus_comp element_mu_co;
element_mu_co.duration = NULL;
return element_mu_co;
}
char sbit[SIZE_NUMBER_IN_FILE+1],sduration[SIZE_NUMBER_IN_FILE+1],sname[MAX_SIZE_NAME];
mus_comp element_mu_co;
strncpy(sbit, &strin[0],SIZE_NUMBER_IN_FILE);
element_mu_co.bit = atoi(sbit);
strncpy(sduration, &strin[SIZE_NUMBER_IN_FILE+1],SIZE_NUMBER_IN_FILE);
element_mu_co.duration = atoi(sduration);
strcpy(element_mu_co.name, &strin[2*(SIZE_NUMBER_IN_FILE+1)]);
return element_mu_co;
}
30 changes: 30 additions & 0 deletions function.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#ifndef FUNCTION_H
#define FUNCTION_H

#include <stdio.h>
#include <string.h>
#include <stdlib.h>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

malloc есть в stdlib.h и в malloc.h

#include <time.h>

#define MAX_SIZE_NAME 30
#define MAX_SIZE_STRING 40
#define SIZE_NUMBER_IN_FILE 3
#define ERROR 404

typedef struct mus_comp mus_comp;

struct mus_comp {
int bit;
int duration;
char name[MAX_SIZE_NAME];
};

mus_comp *add_in_array(mus_comp *array_mu_co,int *SizeArray, int *number_in_array, mus_comp element_mu_co);

int output_info(mus_comp *array_mu_co, int number_in_array);

int find_random_music_composition(mus_comp *array_mu_co, int number_in_array, int coun_element);

mus_comp create_struct_music_composition(char *strin, FILE *fin);

#endif