commit 1a7d9a1e43b5b9c4d27eb036b120bc463d816a4e
parent 98af600139a74eeb6b6100993d60b2a83acd404f
Author: klewer-martin <martin.cachari@gmail.com>
Date: Wed, 21 Apr 2021 12:00:16 -0300
Update: prompt files now contain functions, although they are not working properly yet
Diffstat:
5 files changed, 58 insertions(+), 8 deletions(-)
diff --git a/Makefile b/Makefile
@@ -1,14 +1,17 @@
CC = gcc
FLAGS = -Wall -pedantic
-all: clean main.o matrix.o
- $(CC) $(FLAGS) main.o matrix.o
+all: clean prompt.o matrix.o main.o
+ $(CC) $(FLAGS) main.o matrix.o prompt.o
+
+matrix.o: status.h matrix.h
+ $(CC) $(FLAGS) -c matrix.c
+
+prompt.o:
+ $(CC) $(FLAGS) -c prompt.c
main.o:
$(CC) $(FLAGS) -c main.c
-matrix.o:
- $(CC) $(FLAGS) -c matrix.c
-
clean:
rm -rf *.o
diff --git a/main.c b/main.c
@@ -1,11 +1,12 @@
#include "main.h"
#include "matrix.h"
+#include "prompt.h"
#define R 3
int main (void)
{
- matrix_t matrix;
+/* matrix_t matrix;
matrix_t matrix2;
matrix_t matrix_r;
@@ -13,7 +14,6 @@ int main (void)
m_create(R, R, &matrix2);
m_create(R, R, &matrix_r);
- /*
m_load(N, M, matrix);
m_print(N, M, matrix);
@@ -22,7 +22,6 @@ int main (void)
m_transpose(&matrix, &matrix_transpose);
m_print(&matrix_transpose);
- */
m_load(&matrix);
m_print(&matrix);
@@ -41,5 +40,7 @@ int main (void)
m_destroy(&matrix_r);
+ */
+ prompt_welcome();
return 0;
}
diff --git a/prompt.c b/prompt.c
@@ -1 +1,38 @@
#include "prompt.h"
+
+status_t prompt_welcome(void)
+{
+/* Main loop */
+ while( 1 ) {
+ printf("Welcome to matrix-calculator!\n");
+ printf("What do you want to do?\n");
+ printf("1.- Load a matrix's values of dimensions X x Y by hand.\n");
+ printf("2.- Load a matrix's values with a .txt file.\n");
+ printf("3.- Create a random matrix of dimensions X x Y.\n");
+
+ user_input(MAIN_PROMPT);
+ }
+ return OK;
+}
+
+status_t user_input(user_input_t option)
+{
+ switch (option) {
+ case MAIN_PROMPT:
+ main_prompt();
+ break;
+
+ default: return ERROR_NO_USER_INPUT;
+ }
+ return OK;
+}
+
+status_t main_prompt(void)
+{
+ int i;
+ i = getchar();
+
+ i = (i - '0');
+
+ return OK;
+}
diff --git a/prompt.h b/prompt.h
@@ -4,4 +4,12 @@
#include "matrix.h"
#include "status.h"
+typedef enum {
+ MAIN_PROMPT
+} user_input_t;
+
+status_t prompt_welcome(void);
+status_t user_input(user_input_t option);
+status_t main_prompt(void);
+
#endif
diff --git a/status.h b/status.h
@@ -4,6 +4,7 @@
typedef enum {
OK,
ERROR_MATRIX_DIMENSION,
+ ERROR_NO_USER_INPUT,
ERROR_NULL_POINTER
} status_t;