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