-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack_functions4.c
More file actions
55 lines (53 loc) · 1.11 KB
/
Copy pathstack_functions4.c
File metadata and controls
55 lines (53 loc) · 1.11 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
55
#include "monty.h"
/**
*pchar - prints the string starting at the top of the stack
*@stack: points to a pointer to stack_t list
*@line_number: the number of the current line
*
*
*/
void pchar(stack_t **stack, unsigned int line_number)
{
stack_t *current = *stack;
if (current == NULL)
{
fprintf(stderr, "L%u: can't pchar, stack empty\n", line_number);
exit(EXIT_FAILURE);
}
while (current->next != NULL)
{
current = current->next;
}
if (current->n > 127 || current->n < 0)
{
fprintf(stderr, "L%u: can't pchar, value out of range\n", line_number);
free_list();
exit(EXIT_FAILURE);
}
printf("%c\n", current->n);
}
/**
*rotl - rotates the stack to the top.
*@stack: points to a pointer to a stack_t list
*@line_number: the number of the current line
*
*
*/
void rotl(stack_t **stack, unsigned int line_number)
{
stack_t *first = *stack, *last = *stack;
(void) line_number;
if (first == NULL || first->next == NULL)
{
return;
}
while (last->next != NULL)
{
last = last->next;
}
last->prev->next = NULL;
last->prev = NULL;
last->next = first;
first->prev = last;
*stack = last;
}