-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack_functions_2.c
More file actions
54 lines (52 loc) · 1.03 KB
/
stack_functions_2.c
File metadata and controls
54 lines (52 loc) · 1.03 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
50
51
52
53
54
#include "monty.h"
/**
* op_pchar - prints the char at the top of the stack, followed by a new line
* @stack: head node to the stack
* @line_number: line number of the monty file
* Return: void (EXIT_FAILURE) exit status
*/
void op_pchar(stack_t **stack, unsigned int line_number)
{
int x = 0;
if (*stack == NULL || stack == NULL)
error_func(line_number, 12);
x = (*stack)->n;
if (x >= 1 && x <= 127)
{
putchar(x);
putchar('\n');
}
else
{
printf("L%d: can't pchar, value out of range\n", line_number);
exit(EXIT_FAILURE);
}
}
/**
* op_pstr - prints the string starting at the top of the stack
* @stack: head node to the stack.
* @line_number: line number of the monty file
* Return: void
*/
void op_pstr(stack_t **stack, unsigned int line_number)
{
stack_t *ptr;
int x = 0;
(void)line_number;
if (*stack == NULL || stack == NULL)
putchar('\n');
else
{
ptr = *stack;
while (ptr != NULL)
{
x = ptr->n;
if (x >= 1 && x <= 127)
putchar(x);
else
break;
ptr = ptr->next;
}
putchar('\n');
}
}