diff --git a/Sorting/9Ex/main.c b/Sorting/9Ex/main.c index e649462..8c7f078 100644 --- a/Sorting/9Ex/main.c +++ b/Sorting/9Ex/main.c @@ -1,25 +1,29 @@ #include #include "seagwithsob.h" #include "tools.h" -#include +#include "stdlib.h" int main(void) { FILE * file = getFile(); double * array; + double * orig_arr; int length; if (file == NULL) return -1; array = getArray(file); if (array == NULL) return -2; length = (int)array[0] - 1; - + + orig_arr = array; array = &array[1]; printArray(array, length); sort(array, length); printArray(array, length); + + free(orig_arr); printf("\n"); randomArray(); - + return 0; } diff --git a/Sorting/9Ex/makefile b/Sorting/9Ex/makefile index f750d0b..a33a5fc 100644 --- a/Sorting/9Ex/makefile +++ b/Sorting/9Ex/makefile @@ -1,12 +1,43 @@ +CFLAGS = -mfpmath=sse \ + -fstack-protector-all \ + -W \ + -Wall \ + -Wextra \ + -Wunused \ + -Wcast-align \ + -Werror \ + -pedantic \ + -pedantic-errors \ + -Wfloat-equal \ + -Wpointer-arith \ + -Wformat-security \ + -Wmissing-format-attribute \ + -Wformat=1 \ + -Wwrite-strings \ + -Wcast-align \ + -Wno-long-long \ + -std=gnu99 \ + -Wstrict-prototypes \ + -Wmissing-prototypes \ + -Wmissing-declarations \ + -Wold-style-definition \ + -Wdeclaration-after-statement \ + -Wbad-function-cast \ + -Wnested-externs \ + -O3 \ + -D_DEBUG -g \ + -c + + all: main.o seagwithsob.o tools.o - gcc main.o seagwithsob.o tools.o && rm *.o - ./a.out + gcc main.o seagwithsob.o tools.o -lssp && del *.o + a.exe main.o: main.c - gcc -c main.c + gcc $(CFLAGS) main.c seagwithsob.o: seagwithsob.c - gcc -c seagwithsob.c + gcc $(CFLAGS) seagwithsob.c tools.o: tools.c - gcc -c tools.c + gcc $(CFLAGS) tools.c diff --git a/Sorting/9Ex/seagwithsob.c b/Sorting/9Ex/seagwithsob.c index 8012070..a940880 100644 --- a/Sorting/9Ex/seagwithsob.c +++ b/Sorting/9Ex/seagwithsob.c @@ -28,6 +28,9 @@ void sort(double * array, int length) { for (int i = index; i < length; ++i) array[i] = zero[i - index]; timer += clock(); + free(zero); + free(unit); + printf("Required time for sorting is %lf seconds\n", (double)timer / CLOCKS_PER_SEC); } diff --git a/Sorting/9Ex/tools.c b/Sorting/9Ex/tools.c index edd79c2..723b801 100644 --- a/Sorting/9Ex/tools.c +++ b/Sorting/9Ex/tools.c @@ -64,6 +64,7 @@ void randomArray(void) { sort(array, length); printf("\n"); printArray(array, length); + free(array); } else { printf("Length not entered!\n"); }