-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.c
143 lines (130 loc) · 2.69 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
typedef struct _matrix { //node
unsigned rows;
unsigned cols;
char name; // A-Z
double* arr;
struct matrix *next;
} matrix;
typedef struct _matrixList {
matrix* head;
struct _matrixList* next;
} matrixList;
void mainMenu(void);
void printMenu(void);
void matrixMenu(void);
matrix createMatrix(void);
int readOptions(void);
//void addMatrix2List(void);
int main(void) {
mainMenu();
return 0;
}
void mainMenu() {
system("cls");
printMenu();
switch (readOptions()) {
case 1:
printf("This chapter is too complex! Come back later!");
break;
case 9:
matrixMenu();
break;
default:
printf("No such option exists!");
break;
}
return;
}
void printMenu(void) {
printf("Welcome to the Linear Algebra App!\n");
printf("Please choose an option (1-9) to proceed:\n");
printf("1) Complex Numbers\n");
printf("9) Matrix\n");
return;
}
int readOptions() {
unsigned option = 0;
char buff[21];
do {
printf("Option: ");
fgets(buff, 20, stdin);
} while (sscanf(buff, "%u ", &option) != 1);
return option;
}
void matrixMenu() {
system("cls");
printf("| Matrix Menu |\n");
printf("1) Add Matrix\n");
printf("2) Delete Matrix\n");
printf("3) Return to Main Menu\n");
switch (readOptions()) {
case 1:
createMatrix();
break;
case 2:
printf("ERROR!");
break;
case 3:
mainMenu();
break;
default: // help
break;
}
}
// add matrix - size, values, allocate memory
// delete matrix - free memory
// print matrix - for loop
// print marix list (A-Z, 26 total)
// matrix operations
// return to main menu
// help
matrix createMatrix(void) {
matrix* tmp = (matrix*)malloc(sizeof(matrix));
unsigned r, c;
char buff[21];
r = c = 0;
if (tmp) {
do {
printf("Rows: ");
fgets(buff, 20, stdin);
} while (sscanf(buff, "%u ", &r) != 1);
do {
printf("Columns: ");
fgets(buff, 20, stdin);
} while (sscanf(buff, "%u ", &c) != 1);
if (!tmp) {
return;
}
tmp->rows = r;
tmp->cols = c;
tmp->arr = calloc(r * c, sizeof(double));
printf("Enter the matrix values (by rows):\n");
for (int i = 0; i < r * c; i++) {
scanf("%lf", &tmp->arr[i]);
}
for (int i = 0; i < r * c; i++) {
printf("%5.2lf ", tmp->arr[i]);
if ((i+1) % c == 0)
printf("\n");
}
}
return *tmp;
}
void printMatrix(matrix* m) {
}
//void addMatrix2List(matrixList) {
// if (matrixList == NULL) {
// matrixList->head = martix;
// matrix->name = 'A';
// matrix->next = NULL;
// return;
// }
// matrix* tmp = matrixList->head;
// if (temp != NULL) {
// t
// }
//}