-
Notifications
You must be signed in to change notification settings - Fork 0
/
push.c
44 lines (42 loc) · 812 Bytes
/
push.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
#include "monty.h"
/**
* f_push - Adds a node to the stack.
* @head: Stack head
* @counter: Line number
* Return: No return
*/
void f_push(stack_t **head, unsigned int counter)
{
int num, index = 0, flag = 0;
if (bus.arg)
{
if (bus.arg[0] == '-')
index++;
for (; bus.arg[index] != '\0'; index++)
{
if (bus.arg[index] > '9' || bus.arg[index] < '0')
flag = 1;
}
if (flag == 1)
{
fprintf(stderr, "L%u: usage: push integer\n", counter);
fclose(bus.file);
free(bus.content);
free_stack(*head);
exit(EXIT_FAILURE);
}
}
else
{
fprintf(stderr, "L%u: usage: push integer\n", counter);
fclose(bus.file);
free(bus.content);
free_stack(*head);
exit(EXIT_FAILURE);
}
num = atoi(bus.arg);
if (bus.lifi == 0)
addnode(head, num);
else
addqueue(head, num);
}