-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpush_t.c
44 lines (42 loc) · 825 Bytes
/
push_t.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
#include"monty.h"
/**
* push_t - add node to the stack
* @head: stack head
* @count: line_number
* Return: no return
*/
void push_t(stack_t **head, unsigned int count)
{
int n, i = 0, fnum = 0; /* fnum to check if an elemnt entered isnt num*/
if (glob.arg)
{
if (glob.arg[0] == '-')
i++;
for ( ; glob.arg[i] != '\0'; i++)
{
if (glob.arg[i] > 57 || glob.arg[i] < 48)
fnum = 1;
}
if (fnum == 1)
{
fprintf(stderr, "L%d: usage: push integer\n", count);
fclose(glob.file);
free(glob.content);
free_stack(head);
exit(EXIT_FAILURE);
}
}
else
{
fprintf(stderr, "L%d: 2usage: push integer\n", count);
fclose(glob.file);
free(glob.content);
free_stack(head);
exit(EXIT_FAILURE);
}
n = atoi(glob.arg);
if (glob.isqueue == 0)
push(head, n);
else
pushqueue(head, n);
}