From 9f969fad74e40ba1b40a03e26ef2663897d25457 Mon Sep 17 00:00:00 2001 From: Golem24434 Date: Wed, 13 Oct 2021 20:51:30 +0300 Subject: [PATCH 01/14] start --- DZ1.c | 29 ++++++++++++ DataBase.txt | 125 +++++++++++++++++++++++++++++++++++++++++++++++++++ function.c | 68 ++++++++++++++++++++++++++++ function.h | 25 +++++++++++ 4 files changed, 247 insertions(+) create mode 100644 DZ1.c create mode 100644 DataBase.txt create mode 100644 function.c create mode 100644 function.h diff --git a/DZ1.c b/DZ1.c new file mode 100644 index 0000000..aeb5c9c --- /dev/null +++ b/DZ1.c @@ -0,0 +1,29 @@ +#include +#include +#include +#include +#include +#include "function.h" + +#define MAX_SIZE_NAME 30 +#define MAX_SIZE_STRING 40 +#define SIZE_NUMBER_IN_FILE 3 + +int main() { + srand(time(NULL)); + MusComp *ArrayMuCo = (MusComp*)malloc(1*sizeof(MusComp)); + MusComp ElementMuCo; + char strin[MAX_SIZE_STRING]; + int NumberInArray, SizeArray = 1, inputCount; + 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!"); + for (NumberInArray = 0;NumberInArray < 125;NumberInArray++) { + if (fgets(strin, MAX_SIZE_STRING, fin) == NULL) printf("Error with gets()!"); + ElementMuCo = create_struct_music_composition(strin, fin); + ArrayMuCo = add_in_array(ArrayMuCo, &SizeArray, &NumberInArray, ElementMuCo); + } + scanf("How many tracks do you want to see? %d",&inputCount); + find_random_music_composition(ArrayMuCo,NumberInArray,inputCount); + fclose(fin); + return 0; +} diff --git a/DataBase.txt b/DataBase.txt new file mode 100644 index 0000000..8ce7c95 --- /dev/null +++ b/DataBase.txt @@ -0,0 +1,125 @@ +151 255 Evening Of Silence +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 \ No newline at end of file diff --git a/function.c b/function.c new file mode 100644 index 0000000..a4409b8 --- /dev/null +++ b/function.c @@ -0,0 +1,68 @@ +#include +#include +#include +#include +#include +#include "function.h" + +#define MAX_SIZE_NAME 30 +#define MAX_SIZE_STRING 40 +#define SIZE_NUMBER_IN_FILE 3 + + +MusComp *add_in_array(MusComp *ArrayMuCo,int *SizeArray, int *NumberInArray, MusComp ElementMuCo) + { + if (*NumberInArray + 1 == *SizeArray) + { + (*SizeArray) *= 2; + MusComp *OldPtrArrayMuCo = ArrayMuCo; + ArrayMuCo = (MusComp *) realloc(OldPtrArrayMuCo,(*SizeArray)*sizeof(MusComp)); + if (ArrayMuCo == NULL) printf("Error associated with Realloc() in function add_in_array!"); + } + ArrayMuCo[*NumberInArray] = ElementMuCo; + return ArrayMuCo; +} + +void output_info(MusComp *ArrayMuCo, int NumberInArray) +{ + int i = 0; + while (i != NumberInArray) + { + MusComp ElementMuCo; + ElementMuCo = ArrayMuCo[i]; + printf("\n INDEX[%d]\n Bit: %d \n Duration: %d \n Name: %s\n",i, ElementMuCo.bit, ElementMuCo.duration, ElementMuCo.name); + i++; + } +} + +void find_random_music_composition(MusComp *ArrayMuCo, int NumberInArray, int CountElement) +{ + int randBit = rand()%5 + 150; + int randDuration=rand()%20 + 240; + int OutCount = 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",randBit,randDuration); + while ((OutCount != CountElement+1) && (index < NumberInArray)) + { + if ((abs(ArrayMuCo[index].bit - randBit) <= 1) && (abs(ArrayMuCo[index].duration - randDuration) <= 5)) + { + MusComp ElementMuCo = ArrayMuCo[index]; + printf("\n INDEX[%d]\n Bit: %d \n Duration: %d \n Name: %s\n",OutCount, ElementMuCo.bit, ElementMuCo.duration, ElementMuCo.name); + OutCount++; + } + index++; + } + if (OutCount != CountElement + 1) printf("There are no more music tracks with such parameters."); +} + +MusComp create_struct_music_composition(char *strin, FILE *fin) +{ + char sbit[SIZE_NUMBER_IN_FILE+1],sduration[SIZE_NUMBER_IN_FILE+1],sname[MAX_SIZE_NAME]; + MusComp ElementMuCo; + strncpy(sbit, &strin[0],SIZE_NUMBER_IN_FILE); + ElementMuCo.bit = atoi(sbit); + strncpy(sduration, &strin[SIZE_NUMBER_IN_FILE+1],SIZE_NUMBER_IN_FILE); + ElementMuCo.duration = atoi(sduration); + strcpy(ElementMuCo.name, &strin[2*(SIZE_NUMBER_IN_FILE+1)]); + return ElementMuCo; +} \ No newline at end of file diff --git a/function.h b/function.h new file mode 100644 index 0000000..5889021 --- /dev/null +++ b/function.h @@ -0,0 +1,25 @@ +#include +#include +#include +#include +#include + +#define MAX_SIZE_NAME 30 +#define MAX_SIZE_STRING 40 +#define SIZE_NUMBER_IN_FILE 3 + +typedef struct MusComp MusComp; + +struct MusComp { + int bit; + int duration; + char name[MAX_SIZE_NAME]; +}; + +MusComp *add_in_array(MusComp *ArrayMuCo,int *SizeArray, int *NumberInArray, MusComp ElementMuCo); + +void output_info(MusComp *ArrayMuCo, int NumberInArray); + +void find_random_music_composition(MusComp *ArrayMuCo, int NumberInArray, int CountElement); + +MusComp create_struct_music_composition(char *strin, FILE *fin); From 90394a3f910a5ca11959d43028d40a6c5e697ff6 Mon Sep 17 00:00:00 2001 From: Golem24434 Date: Thu, 14 Oct 2021 13:12:54 +0300 Subject: [PATCH 02/14] checking pointers --- DZ1.c | 40 ++++++++++++++++++++++++++-------------- function.c | 46 +++++++++++++++++++++++++++++++--------------- function.h | 10 ++++++++-- 3 files changed, 65 insertions(+), 31 deletions(-) diff --git a/DZ1.c b/DZ1.c index aeb5c9c..973dbd3 100644 --- a/DZ1.c +++ b/DZ1.c @@ -1,29 +1,41 @@ -#include -#include -#include -#include -#include #include "function.h" -#define MAX_SIZE_NAME 30 -#define MAX_SIZE_STRING 40 -#define SIZE_NUMBER_IN_FILE 3 - int main() { srand(time(NULL)); - MusComp *ArrayMuCo = (MusComp*)malloc(1*sizeof(MusComp)); + MusComp *ArrayMuCo = (MusComp*)malloc(sizeof(MusComp));\ + if (ArrayMuCo == NULL) + { + printf("Error associeted with malloc() in main()!"); + } MusComp ElementMuCo; char strin[MAX_SIZE_STRING]; int NumberInArray, SizeArray = 1, inputCount; 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!"); - for (NumberInArray = 0;NumberInArray < 125;NumberInArray++) { - if (fgets(strin, MAX_SIZE_STRING, fin) == NULL) printf("Error with gets()!"); + if (fin == NULL) + { + printf("Error! File with data can't open!"); + } + for (NumberInArray = 0;NumberInArray < 125;++NumberInArray) { + if (fgets(strin, MAX_SIZE_STRING, fin) == NULL) + { + printf("Error with gets()!"); + } ElementMuCo = create_struct_music_composition(strin, fin); + if (ElementMuCo.duration == NULL) + { + return 0; + } ArrayMuCo = add_in_array(ArrayMuCo, &SizeArray, &NumberInArray, ElementMuCo); + if (ArrayMuCo == NULL) + { + return 0; + } } scanf("How many tracks do you want to see? %d",&inputCount); - find_random_music_composition(ArrayMuCo,NumberInArray,inputCount); + if (find_random_music_composition(ArrayMuCo,NumberInArray,inputCount) == ERROR) + { + return 0; + } fclose(fin); return 0; } diff --git a/function.c b/function.c index a4409b8..984fb17 100644 --- a/function.c +++ b/function.c @@ -1,30 +1,34 @@ -#include -#include -#include -#include -#include #include "function.h" -#define MAX_SIZE_NAME 30 -#define MAX_SIZE_STRING 40 -#define SIZE_NUMBER_IN_FILE 3 - - MusComp *add_in_array(MusComp *ArrayMuCo,int *SizeArray, int *NumberInArray, MusComp ElementMuCo) - { - if (*NumberInArray + 1 == *SizeArray) +{ + if ((ArrayMuCo == NULL) || (SizeArray == NULL)) + { + printf("Error associated with pointers in function add_in_array()!"); + return NULL; + } + if (*NumberInArray + 1 == *SizeArray) { (*SizeArray) *= 2; MusComp *OldPtrArrayMuCo = ArrayMuCo; ArrayMuCo = (MusComp *) realloc(OldPtrArrayMuCo,(*SizeArray)*sizeof(MusComp)); - if (ArrayMuCo == NULL) printf("Error associated with Realloc() in function add_in_array!"); + if (ArrayMuCo == NULL) + { + printf("Error associated with Realloc() in function add_in_array()!"); + } } + ArrayMuCo[*NumberInArray] = ElementMuCo; return ArrayMuCo; } -void output_info(MusComp *ArrayMuCo, int NumberInArray) +int output_info(MusComp *ArrayMuCo, int NumberInArray) { + if (ArrayMuCo == NULL) + { + printf("Error associated with pointers in function output_info()!"); + return ERROR; + } int i = 0; while (i != NumberInArray) { @@ -35,8 +39,13 @@ void output_info(MusComp *ArrayMuCo, int NumberInArray) } } -void find_random_music_composition(MusComp *ArrayMuCo, int NumberInArray, int CountElement) +int find_random_music_composition(MusComp *ArrayMuCo, int NumberInArray, int CountElement) { + if (ArrayMuCo == NULL) + { + printf("Error associated with pointers in function output_info()!"); + return ERROR; + } int randBit = rand()%5 + 150; int randDuration=rand()%20 + 240; int OutCount = 1; @@ -57,6 +66,13 @@ void find_random_music_composition(MusComp *ArrayMuCo, int NumberInArray, int Co MusComp create_struct_music_composition(char *strin, FILE *fin) { + if (strin == NULL) + { + printf("Error associated with pointers in function output_info()!"); + MusComp ElementMuCo; + ElementMuCo.duration = NULL; + return ElementMuCo; + } char sbit[SIZE_NUMBER_IN_FILE+1],sduration[SIZE_NUMBER_IN_FILE+1],sname[MAX_SIZE_NAME]; MusComp ElementMuCo; strncpy(sbit, &strin[0],SIZE_NUMBER_IN_FILE); diff --git a/function.h b/function.h index 5889021..add0a74 100644 --- a/function.h +++ b/function.h @@ -1,3 +1,6 @@ +#ifndef FUNCTION_H +#define FUNCTION_H + #include #include #include @@ -7,6 +10,7 @@ #define MAX_SIZE_NAME 30 #define MAX_SIZE_STRING 40 #define SIZE_NUMBER_IN_FILE 3 +#define ERROR 404 typedef struct MusComp MusComp; @@ -18,8 +22,10 @@ struct MusComp { MusComp *add_in_array(MusComp *ArrayMuCo,int *SizeArray, int *NumberInArray, MusComp ElementMuCo); -void output_info(MusComp *ArrayMuCo, int NumberInArray); +int output_info(MusComp *ArrayMuCo, int NumberInArray); -void find_random_music_composition(MusComp *ArrayMuCo, int NumberInArray, int CountElement); +int find_random_music_composition(MusComp *ArrayMuCo, int NumberInArray, int CountElement); MusComp create_struct_music_composition(char *strin, FILE *fin); + +#endif \ No newline at end of file From 5b0e794c2e63c32ece55738299aca63e4c63ce70 Mon Sep 17 00:00:00 2001 From: Golem24434 Date: Thu, 14 Oct 2021 13:15:11 +0300 Subject: [PATCH 03/14] checking pointers --- .vscode/c_cpp_properties.json | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 .vscode/c_cpp_properties.json diff --git a/.vscode/c_cpp_properties.json b/.vscode/c_cpp_properties.json new file mode 100644 index 0000000..a0f1dc7 --- /dev/null +++ b/.vscode/c_cpp_properties.json @@ -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 +} \ No newline at end of file From 89741816afbff4a0b9cb3d220be893114ec8b019 Mon Sep 17 00:00:00 2001 From: Golem24434 Date: Thu, 14 Oct 2021 15:48:59 +0300 Subject: [PATCH 04/14] snake_case --- DZ1.c | 24 ++++++++++--------- function.c | 70 +++++++++++++++++++++++++++--------------------------- function.h | 13 +++++----- 3 files changed, 54 insertions(+), 53 deletions(-) diff --git a/DZ1.c b/DZ1.c index 973dbd3..cdab437 100644 --- a/DZ1.c +++ b/DZ1.c @@ -2,37 +2,39 @@ int main() { srand(time(NULL)); - MusComp *ArrayMuCo = (MusComp*)malloc(sizeof(MusComp));\ - if (ArrayMuCo == NULL) + mus_comp *array_mu_co = (mus_comp*)malloc(sizeof(mus_comp));\ + if (array_mu_co == NULL) { printf("Error associeted with malloc() in main()!"); } - MusComp ElementMuCo; + mus_comp element_mu_co; char strin[MAX_SIZE_STRING]; - int NumberInArray, SizeArray = 1, inputCount; + 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 (NumberInArray = 0;NumberInArray < 125;++NumberInArray) { + 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; } - ElementMuCo = create_struct_music_composition(strin, fin); - if (ElementMuCo.duration == NULL) + element_mu_co = create_struct_music_composition(strin, fin); + if (element_mu_co.duration == NULL) { return 0; } - ArrayMuCo = add_in_array(ArrayMuCo, &SizeArray, &NumberInArray, ElementMuCo); - if (ArrayMuCo == NULL) + 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",&inputCount); - if (find_random_music_composition(ArrayMuCo,NumberInArray,inputCount) == ERROR) + 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; } diff --git a/function.c b/function.c index 984fb17..b72505b 100644 --- a/function.c +++ b/function.c @@ -1,84 +1,84 @@ #include "function.h" -MusComp *add_in_array(MusComp *ArrayMuCo,int *SizeArray, int *NumberInArray, MusComp ElementMuCo) +mus_comp *add_in_array(mus_comp *array_mu_co,int *SizeArray, int *number_in_array, mus_comp element_mu_co) { - if ((ArrayMuCo == NULL) || (SizeArray == NULL)) + if ((array_mu_co == NULL) || (SizeArray == NULL)) { printf("Error associated with pointers in function add_in_array()!"); return NULL; } - if (*NumberInArray + 1 == *SizeArray) + if (*number_in_array + 1 == *SizeArray) { (*SizeArray) *= 2; - MusComp *OldPtrArrayMuCo = ArrayMuCo; - ArrayMuCo = (MusComp *) realloc(OldPtrArrayMuCo,(*SizeArray)*sizeof(MusComp)); - if (ArrayMuCo == NULL) + 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()!"); } } - ArrayMuCo[*NumberInArray] = ElementMuCo; - return ArrayMuCo; + array_mu_co[*number_in_array] = element_mu_co; + return array_mu_co; } -int output_info(MusComp *ArrayMuCo, int NumberInArray) +int output_info(mus_comp *array_mu_co, int number_in_array) { - if (ArrayMuCo == NULL) + if (array_mu_co == NULL) { printf("Error associated with pointers in function output_info()!"); return ERROR; } int i = 0; - while (i != NumberInArray) + while (i != number_in_array) { - MusComp ElementMuCo; - ElementMuCo = ArrayMuCo[i]; - printf("\n INDEX[%d]\n Bit: %d \n Duration: %d \n Name: %s\n",i, ElementMuCo.bit, ElementMuCo.duration, ElementMuCo.name); + 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(MusComp *ArrayMuCo, int NumberInArray, int CountElement) +int find_random_music_composition(mus_comp *array_mu_co, int number_in_array, int coun_element) { - if (ArrayMuCo == NULL) + if (array_mu_co == NULL) { printf("Error associated with pointers in function output_info()!"); return ERROR; } - int randBit = rand()%5 + 150; - int randDuration=rand()%20 + 240; - int OutCount = 1; + 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",randBit,randDuration); - while ((OutCount != CountElement+1) && (index < NumberInArray)) + 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(ArrayMuCo[index].bit - randBit) <= 1) && (abs(ArrayMuCo[index].duration - randDuration) <= 5)) + if ((abs(array_mu_co[index].bit - rand_bit) <= 1) && (abs(array_mu_co[index].duration - rand_duration) <= 5)) { - MusComp ElementMuCo = ArrayMuCo[index]; - printf("\n INDEX[%d]\n Bit: %d \n Duration: %d \n Name: %s\n",OutCount, ElementMuCo.bit, ElementMuCo.duration, ElementMuCo.name); - OutCount++; + 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 (OutCount != CountElement + 1) printf("There are no more music tracks with such parameters."); + if (out_count != coun_element + 1) printf("There are no more music tracks with such parameters."); } -MusComp create_struct_music_composition(char *strin, FILE *fin) +mus_comp create_struct_music_composition(char *strin, FILE *fin) { if (strin == NULL) { printf("Error associated with pointers in function output_info()!"); - MusComp ElementMuCo; - ElementMuCo.duration = NULL; - return ElementMuCo; + 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]; - MusComp ElementMuCo; + mus_comp element_mu_co; strncpy(sbit, &strin[0],SIZE_NUMBER_IN_FILE); - ElementMuCo.bit = atoi(sbit); + element_mu_co.bit = atoi(sbit); strncpy(sduration, &strin[SIZE_NUMBER_IN_FILE+1],SIZE_NUMBER_IN_FILE); - ElementMuCo.duration = atoi(sduration); - strcpy(ElementMuCo.name, &strin[2*(SIZE_NUMBER_IN_FILE+1)]); - return ElementMuCo; + element_mu_co.duration = atoi(sduration); + strcpy(element_mu_co.name, &strin[2*(SIZE_NUMBER_IN_FILE+1)]); + return element_mu_co; } \ No newline at end of file diff --git a/function.h b/function.h index add0a74..c04979a 100644 --- a/function.h +++ b/function.h @@ -2,7 +2,6 @@ #define FUNCTION_H #include -#include #include #include #include @@ -12,20 +11,20 @@ #define SIZE_NUMBER_IN_FILE 3 #define ERROR 404 -typedef struct MusComp MusComp; +typedef struct mus_comp mus_comp; -struct MusComp { +struct mus_comp { int bit; int duration; char name[MAX_SIZE_NAME]; }; -MusComp *add_in_array(MusComp *ArrayMuCo,int *SizeArray, int *NumberInArray, MusComp ElementMuCo); +mus_comp *add_in_array(mus_comp *array_mu_co,int *SizeArray, int *number_in_array, mus_comp element_mu_co); -int output_info(MusComp *ArrayMuCo, int NumberInArray); +int output_info(mus_comp *array_mu_co, int number_in_array); -int find_random_music_composition(MusComp *ArrayMuCo, int NumberInArray, int CountElement); +int find_random_music_composition(mus_comp *array_mu_co, int number_in_array, int coun_element); -MusComp create_struct_music_composition(char *strin, FILE *fin); +mus_comp create_struct_music_composition(char *strin, FILE *fin); #endif \ No newline at end of file From 2b558a0fdd10f5d7d5e32a68a193d96d22ddfae3 Mon Sep 17 00:00:00 2001 From: Golem24434 Date: Thu, 14 Oct 2021 17:37:27 +0300 Subject: [PATCH 05/14] trevis --- .travis.yml | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..e69de29 From 7d8424760e42e1016b7a5128d812638ea1eab733 Mon Sep 17 00:00:00 2001 From: Golem24434 Date: Thu, 14 Oct 2021 17:41:13 +0300 Subject: [PATCH 06/14] trevis_new --- .travis.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.travis.yml b/.travis.yml index e69de29..0bdf82b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -0,0 +1 @@ +apt install cmake cmake .. make \ No newline at end of file From 13fc240da2246f3c36d7d57d5dc5f2206e99e479 Mon Sep 17 00:00:00 2001 From: Golem24434 Date: Thu, 14 Oct 2021 17:48:14 +0300 Subject: [PATCH 07/14] cmake --- CMakeLists.txt | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 CMakeLists.txt diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..e69de29 From 66233f7c373c0e76b0ad0313944bb86ea320c93e Mon Sep 17 00:00:00 2001 From: Golem24434 Date: Thu, 14 Oct 2021 18:56:31 +0300 Subject: [PATCH 08/14] cmake --- .travis.yml | 18 +++++++++++++++++- CMakeLists.txt | 15 +++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 0bdf82b..4aba6fb 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1 +1,17 @@ -apt install cmake cmake .. make \ No newline at end of file +dist: focal +sudo: required # используем Virtual Machine (а не Docker container) + +language: c + +compiler: + - gcc + +install: + - sudo apt-get install valgrind + - sudo pip3 install cpplint + - sudo apt install cppcheck + +script: +- mkdir IT1/cmake-build-debug && cd IT1/cmake-build-debug/ +- cmake .. +- make clean && make \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index e69de29..afe8745 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -0,0 +1,15 @@ +cmake_minimum_required(VERSION 2.8) # Проверка версии CMake. + # Если версия установленой программы + # старее указаной, произайдёт аварийный выход. + +project(DZ1) # Название проекта + +set(SOURCE_EXE main.c) # Установка переменной со списком исходников для исполняемого файла + +set(SOURCE_LIB foo.c) # Тоже самое, но для библиотеки + +add_library(foo STATIC ${SOURCE_LIB}) # Создание статической библиотеки с именем foo + +add_executable(main ${SOURCE_EXE}) # Создает исполняемый файл с именем main + +target_link_libraries(main foo) # Линковка программы с библиотекой \ No newline at end of file From d76520793283e4f6b62f6393959cbdaa6aa73b59 Mon Sep 17 00:00:00 2001 From: Golem24434 Date: Thu, 14 Oct 2021 19:10:30 +0300 Subject: [PATCH 09/14] mb --- .travis.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.travis.yml b/.travis.yml index 4aba6fb..0bfc1d1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,10 @@ sudo: required # используем Virtual Machine (а не Docker conta language: c +branches: + only: + - other + compiler: - gcc From 43872861e4533cf9545989fdf136619aa06f4f71 Mon Sep 17 00:00:00 2001 From: Golem24434 Date: Thu, 14 Oct 2021 19:21:56 +0300 Subject: [PATCH 10/14] NOIT1 --- DataBase.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DataBase.txt b/DataBase.txt index 8ce7c95..8d4e3c6 100644 --- a/DataBase.txt +++ b/DataBase.txt @@ -1,4 +1,4 @@ -151 255 Evening Of Silence +151 255 Evening Of Siilence 150 251 Town Of Minds 154 248 Fire Of My Beginning 151 257 Dreamy Step From 8a6673711354272c90a7d9c1054acd1e34ff0476 Mon Sep 17 00:00:00 2001 From: Golem24434 Date: Thu, 14 Oct 2021 19:24:11 +0300 Subject: [PATCH 11/14] NO_IT_YES_IZ --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 0bfc1d1..4fb251c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,6 +16,6 @@ install: - sudo apt install cppcheck script: -- mkdir IT1/cmake-build-debug && cd IT1/cmake-build-debug/ +- mkdir IZ1/cmake-build-debug && cd IZ1/cmake-build-debug/ - cmake .. - make clean && make \ No newline at end of file From ebbdd9ab7ae0e14628c8e32532162fdf5c84615c Mon Sep 17 00:00:00 2001 From: Golem24434 Date: Thu, 14 Oct 2021 19:33:07 +0300 Subject: [PATCH 12/14] NO_CMAKEDEBUG --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 4fb251c..bda0d68 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,6 +16,6 @@ install: - sudo apt install cppcheck script: -- mkdir IZ1/cmake-build-debug && cd IZ1/cmake-build-debug/ +- mkdir ./IZ1 && cd ./IZ1 - cmake .. - make clean && make \ No newline at end of file From 4a936c2e9f46c80ed25bc27922ada1f8b8879ed8 Mon Sep 17 00:00:00 2001 From: Golem24434 Date: Thu, 14 Oct 2021 20:53:42 +0300 Subject: [PATCH 13/14] IT1_IZ2 --- CMakeLists.txt | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index afe8745..3419c1f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,15 +1,9 @@ -cmake_minimum_required(VERSION 2.8) # Проверка версии CMake. - # Если версия установленой программы - # старее указаной, произайдёт аварийный выход. +cmake_minimum_required(VERSION 3.20) -project(DZ1) # Название проекта +set(CMAKE_C_STANDARD 99) -set(SOURCE_EXE main.c) # Установка переменной со списком исходников для исполняемого файла +add_library(lib STATIC function.c) -set(SOURCE_LIB foo.c) # Тоже самое, но для библиотеки +add_executable(output ./DZ1.c) -add_library(foo STATIC ${SOURCE_LIB}) # Создание статической библиотеки с именем foo - -add_executable(main ${SOURCE_EXE}) # Создает исполняемый файл с именем main - -target_link_libraries(main foo) # Линковка программы с библиотекой \ No newline at end of file +target_link_libraries(output lib) \ No newline at end of file From 8c71666629005c18b1cdb875fa7ab589b4834d4f Mon Sep 17 00:00:00 2001 From: Golem24434 Date: Thu, 14 Oct 2021 21:08:09 +0300 Subject: [PATCH 14/14] WORKED! --- .travis.yml | 9 +++++++-- CMakeLists.txt | 16 +++++++++++----- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/.travis.yml b/.travis.yml index bda0d68..94b5362 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,6 +3,9 @@ sudo: required # используем Virtual Machine (а не Docker conta language: c +os: + - linux + branches: only: - other @@ -16,6 +19,8 @@ install: - sudo apt install cppcheck script: -- mkdir ./IZ1 && cd ./IZ1 +- mkdir build +- cd build - cmake .. -- make clean && make \ No newline at end of file +- cmake —build . +- ctest —output-on-failure \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 3419c1f..7dca480 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,9 +1,15 @@ -cmake_minimum_required(VERSION 3.20) +cmake_minimum_required(VERSION 3.16) -set(CMAKE_C_STANDARD 99) +project(test) -add_library(lib STATIC function.c) +set(CMAKE_CXX_STANDARD 11) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS}-pthread") -add_executable(output ./DZ1.c) +set(LIB_SOURCE_FILE function.c) +add_library(server STATIC ${LIB_SOURCE_FILE}) -target_link_libraries(output lib) \ No newline at end of file +add_compile_options("-lgcov —coverage") + +add_executable(main DZ1.c) +target_link_libraries(main server) \ No newline at end of file