-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmod.c
More file actions
42 lines (40 loc) · 832 Bytes
/
Copy pathmod.c
File metadata and controls
42 lines (40 loc) · 832 Bytes
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
#include "monty.h"
/**
* _mod - computes the rest of the division of the second
* top element of the stack by the top element of the stack.
* @stack: head
* @num_line: integer
*/
void _mod(stack_t **stack, unsigned int num_line)
{
stack_t *temp1;
stack_t *temp2;
int mult = 0;
if (*stack && (*stack)->next)
{
if ((*stack)->n == 0)
{
dprintf(2, "L%u: division by zero\n", num_line);
free(global.line);
fclose(global.fil);
free_l(stack);
exit(EXIT_FAILURE);
}
temp2 = (*stack)->next;
mult = temp2->n % (*stack)->n;
temp1 = *stack;
*stack = (*stack)->next;
if (*stack)
(*stack)->prev = NULL;
free(temp1);
(*stack)->n = mult;
}
else
{
dprintf(2, "L%d: can't mod, stack too short\n", num_line);
free(global.line);
fclose(global.fil);
free_l(stack);
exit(EXIT_FAILURE);
}
}