-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfind_function.c
72 lines (58 loc) · 1.26 KB
/
find_function.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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include "monty.h"
/**
* my_strdup - my strdup function
* @src: characters to duplicate
* Return: caracter
*/
char *my_strdup(const char *src)
{
size_t len = strlen(src) + 1;
char *dest = malloc(len);
if (dest == NULL)
exit(EXIT_FAILURE);
strcpy(dest, src);
return (dest);
}
/**
* get_instructions - allocate dyna;icqly instructions
* Return: instructions
*/
instruction_t *get_instructions()
{
instruction_t *instructions = malloc(3 * sizeof(instruction_t));
if (instructions == NULL)
{
exit(EXIT_FAILURE);
}
instructions[0].opcode = my_strdup("push");
instructions[0].f = push;
instructions[1].opcode = my_strdup("pall");
instructions[1].f = pall;
instructions[2].opcode = NULL;
instructions[2].f = NULL;
return (instructions);
}
/**
* free_instructions - free instructions
* @instructions: instruction to free
*/
void free_instructions(instruction_t *instructions)
{
free(instructions);
}
/**
* find - find functions
* @opcode: functions variables
* Return: NULL if not found and the fnction struct pointer if fouund
*/
instruction_t *find(char *opcode, instruction_t *instructions)
{
int i = 0;
while (instructions[i].opcode)
{
if (strcmp(instructions[i].opcode, opcode) == 0)
return (&instructions[i]);
i++;
}
return (NULL);
}