-
Notifications
You must be signed in to change notification settings - Fork 2
/
push.c
39 lines (37 loc) · 799 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
#include "monty.h"
/**
* f_push - function that adds node to the stack
* @head: double head pointer to the stack
* @counter: line count
*
* Return: nothing
*/
void f_push(stack_t **head, unsigned int counter)
{
int i, m = 0, flag = 0;
if (bus.arg)
{
if (bus.arg[0] == '-')
m++;
for (; bus.arg[m] != '\0'; m++)
{
if (bus.arg[m] > 57 || bus.arg[m] < 48)
flag = 1; }
if (flag == 1)
{ fprintf(stderr, "L%d: usage: push integer\n", counter);
fclose(bus.file);
free(bus.content);
free_stack(*head);
exit(EXIT_FAILURE); }}
else
{ fprintf(stderr, "L%d: usage: push integer\n", counter);
fclose(bus.file);
free(bus.content);
free_stack(*head);
exit(EXIT_FAILURE); }
i = atoi(bus.arg);
if (bus.lifi == 0)
addnode(head, i);
else
addqueue(head, i);
}