-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmul.c
More file actions
33 lines (29 loc) · 646 Bytes
/
mul.c
File metadata and controls
33 lines (29 loc) · 646 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"
/**
* mul - multiplies the second top element stack
* with the top element of the stack
* @stack: stack
* @line_number: line number of file to execute
*
* Return: void
*/
void mul(stack_t **stack, unsigned int line_number)
{
int val1, val2;
stack_t *temp;
(void) *stack;
temp = file_ptr->head;
if (temp == NULL || count_stacks(file_ptr->head) < 2)
{
fprintf(stderr, "L%d: can't mul, stack too short\n", line_number);
free_file_ptr();
exit(EXIT_FAILURE);
}
val1 = temp->n;
temp = temp->next;
val2 = temp->n;
temp->n = val2 * val1;
free(file_ptr->head);
temp->prev = NULL;
file_ptr->head = temp;
}