-
Notifications
You must be signed in to change notification settings - Fork 0
/
string_ops.c
42 lines (41 loc) · 927 Bytes
/
string_ops.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
#include "monty.h"
/**
* pchar- prints the top data as ascii
* @stack: points to head of stack
* @linenumber: current line no
*
*/
void pchar(stack_t **stack, __attribute__((unused))unsigned int linenumber)
{
if (!(*stack))
{
dprintf(STDERR_FILENO, "L%u: can't pchar, stack empty\n"
, monty.line_number);
free_it_all();
exit(EXIT_FAILURE);
}
if ((*stack)->n < 0 || (*stack)->n > 127)
{
dprintf(STDERR_FILENO, "L%u: can't pchar, value out of range\n",
monty.line_number);
free_it_all();
exit(EXIT_FAILURE);
}
printf("%c\n", (*stack)->n);
}
/**
* pstr- prints stack as a string
* @stack: head of stack
* @linenumber: current line num of monty
*
*/
void pstr(stack_t **stack, __attribute__((unused))unsigned int linenumber)
{
stack_t *location = *stack;
while (location && location->n > 0 && location->n <= 127)
{
putchar(location->n);
location = location->next;
}
putchar('\n');
}