diff --git a/src/cluster.c b/src/cluster.c index fbc62fbdba7889f26509cfc0184be8ff91ce74d6..504c930156d4448a0fcd4ffd373ce246604c4348 100644 --- a/src/cluster.c +++ b/src/cluster.c @@ -8,6 +8,7 @@ cluster_int_t* cluster_create_int(vector_int_t* center) { if (NULL == cluster) return NULL; cluster->center = center; cluster->points = list_points_create_int(); + return cluster; } cluster_fpt_t* cluster_create_fpt(vector_fpt_t* center) { @@ -15,6 +16,7 @@ cluster_fpt_t* cluster_create_fpt(vector_fpt_t* center) { if (NULL == cluster) return NULL; cluster->center = center; cluster->points = list_points_create_fpt(); + return cluster; } diff --git a/src/common.c b/src/common.c index d0954598473a8942531e9f635758652d4a6392af..f249bcdecf4cb7ab9361660a282a562230dfe3c9 100644 --- a/src/common.c +++ b/src/common.c @@ -7,7 +7,7 @@ bool randinit = false; -inline void init_rand() { +void init_rand() { srand(time(NULL)); randinit = true; } diff --git a/src/common.h b/src/common.h index 45cd81268a1c3df64930f0513da6458efd717907..c5a43aae9e3c982bc60c4df4e9be98cb2f066553 100644 --- a/src/common.h +++ b/src/common.h @@ -8,6 +8,8 @@ typedef int64_t int_t; typedef double fpt_t; +void init_rand(); + int rand_int(int max); int rand_int_range(int min, int max); diff --git a/src/io.c b/src/io.c index d6cce4ba75d621b906877d4cd0901dd54f8d94a3..a3674bbdbb6567a828719f473d18cc5ca2ad77db 100644 --- a/src/io.c +++ b/src/io.c @@ -1,5 +1,8 @@ +#define _GNU_SOURCE + #include "io.h" #include <stdio.h> +#include <stdlib.h> #include <string.h> #include "linkedlist.h" #include "vector.h" diff --git a/src/main.c b/src/main.c index b350d4667fb03e2f4ec89d6f9817b93ebe597dc9..c12fe2ce2312976e30e51e4065bcab8dc98b6f29 100644 --- a/src/main.c +++ b/src/main.c @@ -1,10 +1,8 @@ -#define _GNU_SOURCE - +#include <getopt.h> #include <stdbool.h> #include <stdio.h> #include <stdlib.h> #include <string.h> -#include <unistd.h> #include "distance.h" #include "io.h" #include "kmeans.h" @@ -77,12 +75,12 @@ int main_int(const char* ipath, const char* opath, const enum DistanceFunctionTy FILE* ifile = ipath != NULL ? fopen(ipath, "r") : stdin; const size_t dim = io_read_int(ifile); const size_t nb_clusters = io_read_int(ifile); - if (0 <= dim) { + if (0 == dim) { printf("DIMENSION MUST BE STRICTLY POSITIVE !\n"); fclose(ifile); return EXIT_FAILURE; } - if (0 <= nb_clusters) { + if (0 == nb_clusters) { printf("NUMBER OF CLUSTERS MUST BE STRICTLY POSITIVE !\n"); fclose(ifile); return EXIT_FAILURE; @@ -110,12 +108,12 @@ int main_fpt(const char* ipath, const char* opath, const enum DistanceFunctionTy FILE* ifile = ipath != NULL ? fopen(ipath, "r") : stdin; const size_t dim = io_read_int(ifile); const size_t nb_clusters = io_read_int(ifile); - if (0 <= dim) { + if (0 == dim) { printf("DIMENSION MUST BE STRICTLY POSITIVE !\n"); fclose(ifile); return EXIT_FAILURE; } - if (0 <= nb_clusters) { + if (0 == nb_clusters) { printf("NUMBER OF CLUSTERS MUST BE STRICTLY POSITIVE !\n"); fclose(ifile); return EXIT_FAILURE;