mcalc

simple interactive program to perform matrix operations. (WIP)
Index Commits Files Refs README LICENSE
commit 2e62fde61b3edc338398b8fd5402ab474944c3a9
parent bf0f1e4d6d79617b0d4d9bb9713e35de0cf7f26f
Author: klewer-martin <martin.cachari@gmail.com>
Date:   Sun, 25 Apr 2021 23:40:53 -0300

Update;

Diffstat:
Mmain.c | 15++++++++++-----
Mprompt.c | 3+--
Mprompt.h | 2+-
3 files changed, 12 insertions(+), 8 deletions(-)
diff --git a/main.c b/main.c
@@ -2,6 +2,10 @@
 #include "matrix.h"
 #include "prompt.h"
 
+#include <limits.h>
+
+#define MATRIX_ID_MAX_LENGTH 25
+
 int main (void)
 {
     /*
@@ -17,17 +21,18 @@ int main (void)
     m_destroy(&matrix);
     */
     status_t st;
-    static unsigned int *matrix_ids;
+    static matrix_t **matrix_ids;
 
     /*    Only prints the main header    */
     prompt_welcome();
 
-    matrix_ids = (unsigned int *)calloc(MATRIX_IDS_ARRAY_LENGTH, sizeof(int));
-    matrix_t matrix;
+    matrix_ids = (matrix_t **)calloc(MATRIX_IDS_ARRAY_LENGTH, sizeof(matrix_t));
+    for(size_t i = 0; i < MATRIX_IDS_ARRAY_LENGTH; i++)
+        matrix_ids[i] = (matrix_t *)calloc(MATRIX_ID_MAX_LENGTH, sizeof(matrix_t));
 
     /*    The main prompt ask for a matrix interactively and returns a pointer to it    with the values already initialized    */
-    while( 1 ) {
-        if((st = get_matrix(&matrix, matrix_ids)) != OK) {
+    for(size_t i = 0;i < UINT_MAX;i++) {
+        if((st = get_matrix(matrix_ids[i])) != OK) {
             /*    Prompt what do you want to do with the matrix you entered?    */
             printf("%s", "What do you want to do with the matrix you entered?: ");
             return st;
diff --git a/prompt.c b/prompt.c
@@ -19,7 +19,7 @@ status_t user_input(user_input_t option)
     return OK;
 }
 
-status_t get_matrix(matrix_t *matrix, unsigned int *matrix_ids)
+status_t get_matrix(matrix_t *matrix)
 {
     printf("1.- Load a matrix's values of dimensions N x M by hand.\n2.- Load a matrix's values with a .txt file.\n3.- Create a random matrix of dimensions N x M.\nq - exit\n\nWhat do you want to do?: ");
     char *buffer;
@@ -39,7 +39,6 @@ status_t get_matrix(matrix_t *matrix, unsigned int *matrix_ids)
     } else if (buffer[0] == 'q') {
         exit(0);
     }
-    printf("%d\n", matrix_ids[0]);
 
     i = strtol(buffer, NULL, 10);
     if((i < 1) || (i > MAX_MAIN_PROMPT_CMD))
diff --git a/prompt.h b/prompt.h
@@ -17,7 +17,7 @@ typedef enum {
 void prompt_welcome(void);
 
 status_t user_input(user_input_t option);
-status_t get_matrix(matrix_t *matrix, unsigned int *matrix_ids);
+status_t get_matrix(matrix_t *matrix);
 status_t matrix_menu_prompt(void);
 status_t load_m_hand(matrix_t *matrix);