-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathstring_opcodes.c
52 lines (47 loc) · 1 KB
/
string_opcodes.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
#include "monty.h"
/**
* pchar - prints the char at the top of the stack
* @stack: the stack
* @line_number: the index of the current command
*/
void pchar(__attribute__((unused)) stack_t **stack, unsigned int line_number)
{
if (is_empty(monty_list))
{
fprintf(stderr, "L%u: can't pchar, stack empty\n", line_number);
handle_exit();
}
if (is_in_ascii_range(top(monty_list)))
printf("%c\n", top(monty_list));
else
{
fprintf(stderr, "L%u: can't pchar, value out of range\n", line_number);
handle_exit();
}
}
/**
* pstr - prints the string starting at the top of the stack
* @stack: the stack
* @line_number: the index of the current command
*/
void pstr(stack_t **stack, __attribute__((unused)) unsigned int line_number)
{
stack_t *tmp;
if (is_empty(monty_list))
{
putchar('\n');
fflush(stdout);
return;
}
tmp = *stack;
while (tmp != NULL && tmp->n != 0)
{
if (is_in_ascii_range(tmp->n))
putchar(tmp->n);
else
break;
tmp = tmp->next;
}
putchar('\n');
fflush(stdout);
}