-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinput.c
More file actions
49 lines (44 loc) · 1.17 KB
/
Copy pathinput.c
File metadata and controls
49 lines (44 loc) · 1.17 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
/*
** EPITECH PROJECT, 2020
** B-CPE-200-RUN-2-1-matchstick-yann.joubert
** File description:
** remove_stick.c
*/
#include "matchstick.h"
#include "my.h"
int input_null(char *buffer)
{
if (buffer[0] == '\n') {
my_printf("Error: invalid input (positive number expected)\n");
return (84);
}
return (0);
}
sticks_s *reset_input(char *buffer, sticks_s *stick)
{
if (input_null(buffer) == 84)
return (print_messages(stick));
return (stick);
}
sticks_s *print_messages(sticks_s *stick)
{
char *buffer = NULL;
size_t n = 0;
my_printf("%s", "Line: ");
if (getline(&buffer, &n, stdin) < 0)
return (NULL);
reset_input(buffer, stick);
if (check_line(buffer, stick) == 84)
return (print_messages(stick));
stick->line = my_getnbr(buffer);
my_printf("%s", "Matches: ");
if (getline(&buffer, &n, stdin) < 0)
return (NULL);
reset_input(buffer, stick);
if (check_match(buffer, stick) == 84)
return (print_messages(stick));
stick->match = my_getnbr(buffer);
my_printf("Player removed %d match(es) ", stick->match);
my_printf("from line %d\n", stick->line);
return stick;
}