-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchar.c
55 lines (46 loc) · 999 Bytes
/
char.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
#include "monty.h"
#include "lists.h"
/**
* pchar_handler - handles the pchar instruction
* @stack: double pointer to the stack to push to
* @line_number: number of the line in the file
*/
void pchar_handler(stack_t **stack, unsigned int line_number)
{
stack_t *node = *stack;
if (!node)
{
dprintf(STDERR_FILENO, PCHAR_FAIL, line_number);
free_all(1);
exit(EXIT_FAILURE);
}
if (node->n < 0 || node->n > 127)
{
dprintf(STDERR_FILENO, PCHAR_RANGE, line_number);
free_all(1);
exit(EXIT_FAILURE);
}
putchar(node->n);
putchar('\n');
}
/**
* pstr_handler - handles the pstr instruction
* @stack: double pointer to the stack to push to
* @line_number: number of the line in the file
*/
void pstr_handler(stack_t **stack, unsigned int line_number)
{
stack_t *node = *stack;
(void)line_number;
if (!node)
{
putchar('\n');
return;
}
while (node && node->n != 0 && node->n >= 0 && node->n <= 127)
{
putchar(node->n);
node = node->next;
}
putchar('\n');
}