mcalc

simple interactive program to perform matrix operations. (WIP)
Index Commits Files Refs README LICENSE
commit bf0f1e4d6d79617b0d4d9bb9713e35de0cf7f26f
parent 9d3f9be6252a7cb93e90e080313cd2935568e0e3
Author: klewer-martin <martin.cachari@gmail.com>
Date:   Fri, 23 Apr 2021 13:52:06 -0300

Update: added matrix_ids array to store the matrix created

Diffstat:
Mmain.c | 4+++-
Mmatrix.c | 2+-
Mprompt.c | 4++--
Mprompt.h | 3++-
4 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/main.c b/main.c
@@ -17,15 +17,17 @@ int main (void)
     m_destroy(&matrix);
     */
     status_t st;
+    static unsigned int *matrix_ids;
 
     /*    Only prints the main header    */
     prompt_welcome();
 
+    matrix_ids = (unsigned int *)calloc(MATRIX_IDS_ARRAY_LENGTH, sizeof(int));
     matrix_t matrix;
 
     /*    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)) != OK) {
+        if((st = get_matrix(&matrix, matrix_ids)) != 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/matrix.c b/matrix.c
@@ -43,7 +43,7 @@ status_t m_load(matrix_t *matrix)
     for(size_t i = 0; i < matrix->rows; i++) {
         for(size_t j = 0; j < matrix->columns; j++) {
             empty_string(buf, MAX_IN_LEN);
-            printf("Enter value %ld%ld of the matrix: ", i, j);
+            printf("Enter value %ld%ld: ", i, j);
             for(size_t k = 0; ((aux = getchar()) != '\n') && k < MAX_IN_LEN; k++)
                 if(isdigit(aux) || (aux == '.') || (aux == '-'))
                     buf[k] = aux;
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)
+status_t get_matrix(matrix_t *matrix, unsigned int *matrix_ids)
 {
     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,7 @@ status_t get_matrix(matrix_t *matrix)
     } 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
@@ -8,6 +8,7 @@
 
 #define MAX_MAIN_PROMPT_CMD 3
 #define SIZE_OF_BUFFER 10
+#define MATRIX_IDS_ARRAY_LENGTH 128
 
 typedef enum {
     MAIN_PROMPT
@@ -16,7 +17,7 @@ typedef enum {
 void prompt_welcome(void);
 
 status_t user_input(user_input_t option);
-status_t get_matrix(matrix_t *matrix);
+status_t get_matrix(matrix_t *matrix, unsigned int *matrix_ids);
 status_t matrix_menu_prompt(void);
 status_t load_m_hand(matrix_t *matrix);