-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathadd_nodetoken_end.c
More file actions
40 lines (33 loc) · 839 Bytes
/
add_nodetoken_end.c
File metadata and controls
40 lines (33 loc) · 839 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 "lists.h"
/**
* add_nodetoken_end - adds a new node at the end of a listtoken_t list
*
* Description: function adds a new node to the end f the linked list
*
* @head: points to a pointer that points to the first node
* @token: the token to add
*
* Return: the address of the new element, or NULL if it failed
*/
listtoken_t *add_nodetoken_end(listtoken_t **head, char *token)
{
listtoken_t *new_node, *last_node;
if (head == NULL)
return (NULL);
new_node = malloc(sizeof(listtoken_t));
if (new_node == NULL)
return (NULL);
new_node->token = token;
new_node->token_length = strlen(token);
new_node->next = NULL;
if (*head == NULL)
*head = new_node;
else
{
last_node = *head;
while (last_node->next != NULL)
last_node = last_node->next;
last_node->next = new_node;
}
return (last_node);
}