-
Notifications
You must be signed in to change notification settings - Fork 0
/
adv_funcs.c
executable file
·104 lines (84 loc) · 2.03 KB
/
adv_funcs.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
92
93
94
95
96
97
98
99
100
101
102
103
104
#include "monty.h"
/**
* mod - Compute the rest of the division of second element
* by the top element in stack.
*
* @head: A void value passed by necessity.
* @line_number: A void value pass by necessity.
*/
void mod(stack_t **head, unsigned int line_number)
{
stack_t *temp;
int result = 0;
(void) head;
(void) line_number;
if (manager->h == NULL || manager->h->next == NULL)
error_print3(13);
if (manager->h->n == 0)
error_print3(11);
temp = manager->h;
manager->h = manager->h->next;
result = (manager->h->n) % (temp->n);
manager->h->n = result;
manager->h->prev = NULL;
free(temp);
}
void pchar(stack_t **head, unsigned int line_number)
{
(void) head;
(void) line_number;
if (manager->h == NULL)
error_print3(14);
if (manager->h->n < 0 || manager->h->n > 127)
error_print3(15);
putchar(manager->h->n + '0');
putchar('\n');
}
void pstr(stack_t **head, unsigned int line_number)
{
(void) head;
(void) line_number;
while (manager->h->n != 0 && manager->h != NULL)
{
if ((manager->h->n >= 97 && manager->h->n <= 122) ||
(manager->h->n >= 65 && manager->h->n <= 90))
putchar(manager->h->n);
else
break;
manager->h = manager->h->next;
}
printf("\n");
}
void rotl(stack_t **head, unsigned int line_number)
{
stack_t *search;
stack_t *hold;
(void) head;
(void) line_number;
if (manager->h == NULL || manager->h->next == NULL)
return;
search = manager->h;
hold = manager->h->next;
while (search->next != NULL)
search = search->next;
search->next = manager->h;
hold->prev = NULL;
manager->h->next = NULL;
manager->h = hold;
}
void rotr(stack_t **head, unsigned int line_number)
{
stack_t *search;
(void) head;
(void) line_number;
if (manager->h == NULL || manager->h->next == NULL)
return;
search = manager->h;
while (search->next != NULL)
search = search->next;
search->next = manager->h;
manager->h->prev = search;
search->prev->next = NULL;
search->prev = NULL;
manager->h = search;
}