-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparse.c
More file actions
36 lines (29 loc) · 914 Bytes
/
Copy pathparse.c
File metadata and controls
36 lines (29 loc) · 914 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
#include "header.h"
char **parse_line(char *line) {
int buffer_size = BUFFER_SIZE, position = 0;
char **tokens = malloc(buffer_size * sizeof(char *));
char *token;
if (!tokens) {
fprintf(stderr, "Allocation error\n");
exit(EXIT_FAILURE);
}
token = strtok(line, TOKEN_DELIMITER);
while (token != NULL) {
tokens[position] = token;
position++;
if (position >= buffer_size) {
buffer_size += BUFFER_SIZE;
tokens = realloc(tokens, buffer_size * sizeof(char *));
if (!tokens) {
fprintf(stderr, "Allocation error\n");
exit(EXIT_FAILURE);
}
}
token = strtok(NULL, TOKEN_DELIMITER);
}
tokens[position] = NULL;
//printing the tokens
//for(int i =0 ; tokens[i]!= NULL ; i++)
// printf("@%s@\n",tokens[i]);
return tokens;
}