mcalc

simple interactive program to perform matrix operations. (WIP)
Index Commits Files Refs README LICENSE
prompt.c (2205B)
   1 #include "prompt.h"
   2 
   3 void prompt_welcome(void)
   4 {
   5     printf("%s", "Welcome to matrix-calculator!\n\n");
   6     /*
   7     printf("Welcome to matrix-calculator!\n\n1.- 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.\n\nWhat do you want to do?: ");
   8     */
   9 }
  10 
  11 status_t user_input(user_input_t option)
  12 {
  13     switch (option) {
  14         case MAIN_PROMPT:
  15             break;
  16         
  17         default: return ERROR_NO_USER_INPUT;
  18     }
  19     return OK;
  20 }
  21 
  22 status_t get_matrix(matrix_t *matrix, matrix_t **matrix_ids)
  23 {
  24     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?: ");
  25     char *buffer;
  26     size_t i;
  27 
  28     buffer = (char *)malloc(DIM_BUFFER_MAX_SIZE * sizeof(char));
  29     if(buffer == NULL) return ERROR_ALLOCATING_MEMORY;
  30 
  31     empty_string(buffer, DIM_BUFFER_MAX_SIZE);
  32 
  33     fgets(buffer, DIM_BUFFER_MAX_SIZE, stdin);
  34     if(buffer[0] == '\n') {
  35         while(buffer[0] == '\n') {
  36             printf("%s", "What do you want to do?: ");
  37             fgets(buffer, DIM_BUFFER_MAX_SIZE, stdin);
  38         }
  39     } else if (buffer[0] == 'q') {
  40         exit(0);
  41     }
  42 
  43     i = strtol(buffer, NULL, 10);
  44     if((i < 1) || (i > MAX_MAIN_PROMPT_CMD))
  45         return ERROR_MAX_MAIN_PROMPT_REACHED;
  46 
  47     empty_string(buffer, DIM_BUFFER_MAX_SIZE);
  48 
  49     putchar('\n');
  50     switch(i) {
  51         case 1:
  52             {
  53                 /*    Enter the matrix Number(1 .. 128, Default 1):    */
  54                 printf("%s", "Enter the matrix id number (1 .. 128, Default 1): ");
  55 
  56                 fgets(buffer, DIM_BUFFER_MAX_SIZE, stdin);
  57                 if(buffer[0] == '\n') {
  58                     i = 1;
  59                 } else {
  60                     i = strtol(buffer, NULL, 10);
  61                 }
  62 
  63                 /*    Now i contains the ID of the created matrix    */
  64                 matrix->id = i;
  65                 printf("The id you entered is: %lu\n", matrix->id);
  66 
  67                 /*    Now we ask for the dimensions of the matrix    */
  68                 m_load_dim(matrix);
  69 
  70                 /*    And we create the matrix    */
  71                 m_create(matrix->rows, matrix->columns, matrix);
  72 
  73                 putchar('\n');
  74                 m_load(matrix);
  75                 printf("%s", "The matrix you entered is: \n");
  76                 m_print(matrix);
  77                 putchar('\n');
  78         }
  79     }
  80 
  81     free(buffer);
  82     return OK;
  83 }