-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmatrix_utils.c
More file actions
61 lines (46 loc) · 1.1 KB
/
matrix_utils.c
File metadata and controls
61 lines (46 loc) · 1.1 KB
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
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include "mymat.h"
extern matrix matrices[MATRICES_SIZE];
/* Get the matrix */
matrix *get_matrix(char *name) {
int i;
for (i = 0; i < MATRICES_SIZE; i++) {
if (strcmp(name, matrices[i].name) == 0) {
return &matrices[i];
}
}
return NULL;
}
/* Get the matrix data from the matrix */
mat *get_matrix_data(matrix *matrix_var) {
return matrix_var == NULL? NULL : (*matrix_var).matrix;
}
void print_matrix(mat *matrix_data) {
int i, j;
printf("-----------------------------\n");
for (i = 0; i < ROW; i++) {
for (j = 0; j < COL; j++) {
printf("%.2f \t", (*matrix_data).data[i][j]);
}
printf("\n");
}
printf("-----------------------------\n");
}
/* Strip string prefix and suffix */
char *strstrip(char *s) {
size_t size;
char *end;
size = strlen(s);
if (!size)
return s;
end = s + size - 1;
while (end >= s && isspace(*end))
end--;
*(end + 1) = '\0';
while (*s && isspace(*s))
s++;
return s;
}
int min(int a, int b) { return (a > b) ? b : a; }