-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
56 lines (50 loc) · 817 Bytes
/
main.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
45
46
47
48
49
50
51
52
53
54
55
56
#include "monty.h"
stack_t *head = NULL;
/**
* main - Entry Point.
*
* @argc: argument count.
* @argv: array of arguments.
*
* Return: (0) on Success, (1) if error occured.
*/
int main(int argc, char *argv[])
{
if (argc != 2)
{
error(1);
exit(EXIT_FAILURE);
}
if (openfile(argv[1]) == 3)
return (1);
return (0);
}
/**
* create_node - Creates a node.
* @n: Number to go inside the node.
* Return: Upon sucess a pointer to the node. Otherwise NULL.
*/
stack_t *create_node(int n)
{
stack_t *node;
node = malloc(sizeof(stack_t));
if (node == NULL)
error(3);
node->next = NULL;
node->prev = NULL;
node->n = n;
return (node);
}
/**
* free_nodes - free stack nodes.
*/
void free_nodes(void)
{
stack_t *tmp = head;
while (tmp)
{
tmp = head->next;
free(head);
head = tmp;
}
}