-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharrayofpointers.c
More file actions
40 lines (32 loc) · 852 Bytes
/
arrayofpointers.c
File metadata and controls
40 lines (32 loc) · 852 Bytes
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
#include <stdio.h>
#include <stdlib.h>
typedef struct Token {
char *literal;
int line;
int column;
} token_t;
token_t** create_token_pointer_array(token_t* tokens, size_t count)
{
// create an array of the correct size
token_t** token_pointers = malloc(count * sizeof(token_t*));
if (token_pointers == NULL)
{
fprintf(stderr, "Memory allocation failed\n");
exit(1);
}
for (size_t i = 0; i < count; i++)
{
// create a new token pointer
token_t *pointer = malloc(sizeof(token_t));
// set the value
token_pointers[i] = pointer;
// copy each value over to each posiiton in the array
// could also be written as *token_pointers[i] = tokens[i]; // same thing
*pointer = tokens[i];
}
return token_pointers;
}
int main()
{
return 0;
}