0x12. C Singly linked lists Task 3 - humtej1204/holbertonschool-low_level_programming GitHub Wiki
mandatory
Write a function that adds a new node at the end of a list_t list.
- Prototype:
list_t *add_node_end(list_t **head, const char *str);
- Return: the address of the new element, or
NULL
if it failed -
str
needs to be duplicated - You are allowed to use
strdup
julien@ubuntu:~/0x12. Singly linked lists$ cat 3-main.c
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "lists.h"
/**
* main - check the code
*
* Return: Always 0.
*/
int main(void)
{
list_t *head;
head = NULL;
add_node_end(&head, "Anne");
add_node_end(&head, "Colton");
add_node_end(&head, "Corbin");
add_node_end(&head, "Daniel");
add_node_end(&head, "Danton");
add_node_end(&head, "David");
add_node_end(&head, "Gary");
add_node_end(&head, "Holden");
add_node_end(&head, "Ian");
add_node_end(&head, "Ian");
add_node_end(&head, "Jay");
add_node_end(&head, "Jennie");
add_node_end(&head, "Jimmy");
add_node_end(&head, "Justin");
add_node_end(&head, "Kalson");
add_node_end(&head, "Kina");
add_node_end(&head, "Matthew");
add_node_end(&head, "Max");
add_node_end(&head, "Michael");
add_node_end(&head, "Ntuj");
add_node_end(&head, "Philip");
add_node_end(&head, "Richard");
add_node_end(&head, "Samantha");
add_node_end(&head, "Stuart");
add_node_end(&head, "Swati");
add_node_end(&head, "Timothy");
add_node_end(&head, "Victor");
add_node_end(&head, "Walton");
print_list(head);
return (0);
}
julien@ubuntu:~/0x12. Singly linked lists$ gcc -Wall -pedantic -Werror -Wextra -std=gnu89 3-main.c 3-add_node_end.c 0-print_list.c -o d
julien@ubuntu:~/0x12. Singly linked lists$ ./d
[4] Anne
[6] Colton
[6] Corbin
[6] Daniel
[6] Danton
[5] David
[4] Gary
[6] Holden
[3] Ian
[3] Ian
[3] Jay
[6] Jennie
[5] Jimmy
[6] Justin
[6] Kalson
[4] Kina
[7] Matthew
[3] Max
[7] Michael
[4] Ntuj
[6] Philip
[7] Richard
[8] Samantha
[6] Stuart
[5] Swati
[7] Timothy
[6] Victor
[6] Walton
julien@ubuntu:~/0x12. Singly linked lists$
- GitHub repository: holbertonschool-low_level_programming
- Directory: 0x12-singly_linked_lists
- File: 3-add_node_end.c