diff options
| author | Elizabeth Hunt <elizabeth.hunt@simponic.xyz> | 2023-10-11 17:00:38 -0600 |
|---|---|---|
| committer | Elizabeth Hunt <elizabeth.hunt@simponic.xyz> | 2023-10-11 17:00:38 -0600 |
| commit | add2520e49da79357b7759d65f7c0863d88669b3 (patch) | |
| tree | 90806fe6a03774ce65b0fd1269037452763994d2 /src/vector.c | |
| parent | 78bd8c4a95049fcd738156a6244635c822044915 (diff) | |
| download | math-4610-add2520e49da79357b7759d65f7c0863d88669b3.tar.gz math-4610-add2520e49da79357b7759d65f7c0863d88669b3.zip | |
bug fixes and fix compilation on gcc
Diffstat (limited to 'src/vector.c')
| -rw-r--r-- | src/vector.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/vector.c b/src/vector.c index e6e2544..a7ff783 100644 --- a/src/vector.c +++ b/src/vector.c @@ -2,6 +2,7 @@ #include <assert.h> #include <float.h> #include <math.h> +#include <string.h> #include <stdio.h> double l2_norm(Array_double *v) { @@ -100,10 +101,17 @@ void free_vector(Array_double *v) { } void format_vector_into(Array_double *v, char *s) { - sprintf(s, ""); - if (v->size == 0) - sprintf(s, "empty"); + if (v->size == 0) { + strcat(s, "empty"); + return; + } - for (size_t i = 0; i < v->size; ++i) - sprintf(s, "%s %f,", s, v->data[i]); + for (size_t i = 0; i < v->size; ++i) { + char num[64]; + strcpy(num, ""); + + sprintf(num, "%f,", v->data[i]); + strcat(s, num); + } + strcat(s, "\n"); } |
