-
Notifications
You must be signed in to change notification settings - Fork 0
/
print_operations.c
91 lines (86 loc) · 1.69 KB
/
print_operations.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "monty.h"
/**
* pall - print all nodes in stack
* @h: head of list
* @line_number: bytecode line number
*/
void pall(stack_t **h, unsigned int line_number)
{
stack_t *tmp = NULL;
if (!h || !*h)
return;
(void) line_number;
tmp = *h;
while (tmp != NULL)
{
printf("%d\n", tmp->n);
tmp = tmp->next;
}
}
/**
* pint - print top node in stack
* @h: head of list
* @line_number: bytecode line number
*/
void pint(stack_t **h, unsigned int line_number)
{
if (!h || !*h)
{
printf("L%u: can't pint, stack empty\n", line_number);
exit(EXIT_FAILURE);
}
printf("%d\n", (*h)->n);
}
/**
* pchar - print top node in stack as ascii letter
* @h: head of list
* @line_number: bytecode line number
*/
void pchar(stack_t **h, unsigned int line_number)
{
if (!h || !*h)
{
printf("L%u: can't pchar, stack empty\n", line_number);
exit(EXIT_FAILURE);
}
if (((*h)->n) >= 0 && ((*h)->n) <= 127)
printf("%c\n", (*h)->n);
else
{
printf("L%u: can't pchar, value out of range\n", line_number);
exit(EXIT_FAILURE);
}
}
/**
* pstr - print top nodes in stack as ascii letter
* and stop only if end of stack, node is 0, or not in ascii table
* @h: head of list
* @line_number: bytecode line number
*/
void pstr(stack_t **h, unsigned int line_number)
{
stack_t *tmp;
if (!h || !*h)
{
printf("L%u: can't pchar, stack empty\n", line_number);
exit(EXIT_FAILURE);
}
tmp = *h;
while ((tmp != NULL) && (tmp->n != 0) &&
(tmp->n >= 0) && (tmp->n <= 127))
{
printf("%c", (tmp)->n);
tmp = tmp->next;
}
printf("\n");
}
/**
* nop - do nothing
* @h: head of list
* @line_number: bytecode line number
*/
void nop(stack_t **h, unsigned int line_number)
{
(void) h;
(void) line_number;
}