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