-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinked_lists.c
More file actions
47 lines (44 loc) · 769 Bytes
/
linked_lists.c
File metadata and controls
47 lines (44 loc) · 769 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
41
42
43
44
45
46
47
#include "simple_shell.h"
/**
* develop_likedlist - forms an empty path based on arguments
* @s: pointer to the formed path variable
* Return: pointer to the path_t struct
*/
path_t *develop_likedlist(char *s)
{
int _nodes = 1;
int k = 0;
path_t *last, *h, *temp, *_node;
temp = malloc(sizeof(path_t));
if (temp == NULL)
return (NULL);
h = temp;
last = malloc(sizeof(path_t));
if (last == NULL)
{
free(temp);
return (NULL);
}
last->next = NULL;
while (s[k] != '\0')
{
if (s[k] == ':')
_nodes++;
k++;
}
while ((_nodes - 2) > 0)
{
_node = malloc(sizeof(path_t));
if (_node == NULL)
{
free(temp);
free(last);
return (NULL);
}
temp->next = _node;
temp = temp->next;
_nodes--;
}
temp->next = last;
return (h);
}