-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStackStringOps.c
More file actions
82 lines (79 loc) · 1.87 KB
/
Copy pathStackStringOps.c
File metadata and controls
82 lines (79 loc) · 1.87 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
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
#include "monty.h"
/**
* PrintStr - Prints a string.
* @stack: Points to a pointer pointing to top node of the stack.
* @LineNumber: line number of of the opcode.
*/
void PrintStr(stack_t **stack, __attribute__((unused))unsigned int LineNumber)
{
int ascii;
stack_t *temp;
if (stack == NULL || *stack == NULL)
{
printf("\n");
return;
}
temp = *stack;
while (temp != NULL)
{
ascii = temp->n;
if (ascii <= 0 || ascii > 127)
break;
printf("%c", ascii);
temp = temp->next;
}
printf("\n");
}
/**
* PrintChar - Prints ASCII value.
* @stack: Points to a pointer pointing to top node of the stack.
* @LineNumber: line number of of the opcode.
*/
void PrintChar(stack_t **stack, unsigned int LineNumber)
{
int ascii;
if (stack == NULL || *stack == NULL)
StringError(11, LineNumber);
ascii = (*stack)->n;
if (ascii < 0 || ascii > 127)
StringError(10, LineNumber);
printf("%c\n", ascii);
}
/**
* rotr - Rotates the last node of the stack to the top.
* @stack: Points to a pointer pointing to top node of the stack.
* @LineNumber: line number of of the opcode.
*/
void rotr(stack_t **stack, __attribute__((unused))unsigned int LineNumber)
{
stack_t *temp;
if (stack == NULL || *stack == NULL || (*stack)->next == NULL)
return;
temp = *stack;
while (temp->next != NULL)
temp = temp->next;
temp->next = *stack;
temp->prev->next = NULL;
temp->prev = NULL;
(*stack)->prev = temp;
(*stack) = temp;
}
/**
* rotl - Rotates the first node of the stack to the bottom.
* @stack: Points to a pointer pointing to top node of the stack.
* @LineNumber: line number of of the opcode.
*/
void rotl(stack_t **stack, __attribute__((unused))unsigned int LineNumber)
{
stack_t *temp;
if (stack == NULL || *stack == NULL || (*stack)->next == NULL)
return;
temp = *stack;
while (temp->next != NULL)
temp = temp->next;
temp->next = *stack;
(*stack)->prev = temp;
*stack = (*stack)->next;
(*stack)->prev->next = NULL;
(*stack)->prev = NULL;
}