-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate_map.c
More file actions
61 lines (56 loc) · 1.3 KB
/
Copy pathgenerate_map.c
File metadata and controls
61 lines (56 loc) · 1.3 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
/*
** EPITECH PROJECT, 2024
** B-CPE-110-LYN-1-1-settingup-pierre.riss
** File description:
** generate_map.c
*/
#include "include/other_libs.h"
#include "lib/my/libmy.h"
#include "include/my.h"
#include <stdlib.h>
static void error_handling(char *motif, char *size)
{
for (int i = 1; motif[i] != '\0'; i++){
if (!(motif[i] == 'o' || motif[i] == '.')){
my_puterror("Invalide motif\n");
exit(84);
}
}
if (!is_number(size)){
my_puterror("Invalide given paramter, should be a number\n");
exit(84);
}
if (str_to_int(size) <= 0){
my_puterror("Invalide size\n");
exit(84);
}
}
static char boucle_str(char *motif, int *j)
{
char c;
if (motif[(*j)] == '\0'){
(*j) = 1;
return motif[0];
}
c = motif[(*j)];
(*j)++;
return c;
}
char *generate_map(char *motif, char *size)
{
char *str;
int isize;
int j = 0;
int x = 0;
error_handling(motif, size);
isize = str_to_int(size);
str = malloc(((isize * isize) + isize + 1));
for (; x < isize; x++){
for (int y = 0; y <= isize - 1; y++){
str[(((x * isize)) + y + x)] = boucle_str(motif, &j);
}
str[((x * isize) + isize + x)] = '\n';
}
str[((x * isize) + isize)] = '\0';
return str;
}