summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main.c7
-rw-r--r--src/matrix.c12
-rw-r--r--src/vector.c20
3 files changed, 21 insertions, 18 deletions
diff --git a/src/main.c b/src/main.c
deleted file mode 100644
index 6bb704a..0000000
--- a/src/main.c
+++ /dev/null
@@ -1,7 +0,0 @@
-#include "lizfcm.h"
-#include <stdio.h>
-
-int main() {
- printf("hello, from lizfcm!\n");
- return 0;
-}
diff --git a/src/matrix.c b/src/matrix.c
index a23aad4..953d50f 100644
--- a/src/matrix.c
+++ b/src/matrix.c
@@ -1,5 +1,6 @@
#include "lizfcm.h"
#include <assert.h>
+#include <string.h>
#include <stdio.h>
void put_identity_diagonal(Matrix_double *m) {
@@ -69,14 +70,15 @@ void free_matrix(Matrix_double *m) {
}
void format_matrix_into(Matrix_double *m, char *s) {
- sprintf(s, "");
if (m->rows == 0)
- sprintf(s, "empty");
+ strcpy(s, "empty");
for (size_t y = 0; y < m->rows; ++y) {
- char *row_s = malloc(sizeof(char) * 256);
+ char row_s[256];
+ strcpy(row_s, "");
+
format_vector_into(m->data[y], row_s);
- sprintf(s, "%s %s \n", s, row_s);
- free(row_s);
+ strcat(s, row_s);
}
+ strcat(s, "\n");
}
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");
-
- for (size_t i = 0; i < v->size; ++i)
- sprintf(s, "%s %f,", s, v->data[i]);
+ if (v->size == 0) {
+ strcat(s, "empty");
+ return;
+ }
+
+ 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");
}