-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsu_load.c
138 lines (127 loc) · 2.08 KB
/
su_load.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
/*
** su_load.c for su_load in /home/enzo/rendu/prog/sudoki-bi
**
** Made by Enzo
** Login <enzo@enzo-HP-EliteBook-840-G2>
**
** Started on Fri Feb 26 22:15:55 2016 Enzo
** Last update Sun Feb 28 22:36:28 2016 Enzo
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include "sudo.h"
char *pars_and_stack(char *str)
{
int i;
int j;
char *stack;
j = 0;
i = 0;
if (NULL == (stack = malloc(sizeof(int) * 9)))
return (NULL);
while (str[i])
{
if ((str[i] > '0' || str[i] <= '9') && str[i] != '|')
{
stack[j] = str[i];
j++;
}
else if (str[i] == ' ')
{
stack[j] = 0;
j++;
}
i = i + 2;
}
return (stack);
}
char **tab_ofchar(int fd)
{
int i;
char **tab;
i = 0;
if (NULL == (tab = malloc(sizeof(char*) * 9)))
return (NULL);
while (i < 8)
{
if (NULL == (tab[i] = malloc(sizeof(char) * 9)))
return (NULL);
i++;
}
get_next_line(fd);
i = 0;
while (i < 9)
{
tab[i] = get_next_line(fd);
i++;
}
return (tab);
}
int **from_chartoint(char **tab)
{
int i;
int **map;
int j;
i = 0;
if (NULL == (map = malloc(sizeof(int*) * 11)))
return (NULL);
while (i < 9)
{
if (NULL == (map[i] = malloc(sizeof(int) * 11)))
return (NULL);
i++;
}
map = complete_cti(tab, map);
return (map);
}
void aff_map(int **map)
{
int i;
int j;
j = 0;
printf("|------------------|\n");
while (j < 9)
{
i = 0;
printf("| ");
while (i < 9)
{
if (i == 8)
printf("%d|\n", map[j][i]);
else
printf("%d ", map[j][i]);
i = i + 1;
}
j = j + 1;
}
printf("|------------------|\n");
}
int main()
{
char **tab;
int **map;
int fd;
int i;
i = 0;
fd = 0;
tab = tab_ofchar(fd);
if (map_isbad(tab) == 0)
{
printf("MAP ERROR\n");
return (0);
}
while (i < 9)
{
tab[i] = pars_and_stack(tab[i]);
i++;
}
map = from_chartoint(tab);
if (validate(map, 0) == false)
sudoku_insolvent();
else
aff_map(map);
}