0x13. C More singly linked lists Task 12 - humtej1204/holbertonschool-low_level_programming GitHub Wiki
#advanced
Write a function that prints a listint_t
linked list.
- Prototype:
size_t print_listint_safe(const listint_t *head);
- Returns: the number of nodes in the list
- This function can print lists with a loop
- You should go through the list only once
- If the function fails, exit the program with status
98
- Output format: see example
julien@ubuntu:~/0x13. More singly linked lists$ cat 101-main.c
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include "lists.h"
/**
* main - check the code
*
* Return: Always 0.
*/
int main(void)
{
listint_t *head;
listint_t *head2;
listint_t *node;
head2 = NULL;
add_nodeint(&head2, 0);
add_nodeint(&head2, 1);
add_nodeint(&head2, 2);
add_nodeint(&head2, 3);
add_nodeint(&head2, 4);
add_nodeint(&head2, 98);
add_nodeint(&head2, 402);
add_nodeint(&head2, 1024);
print_listint_safe(head2);
head = NULL;
node = add_nodeint(&head, 0);
add_nodeint(&head, 1);
add_nodeint(&head, 2);
add_nodeint(&head, 3);
add_nodeint(&head, 4);
node->next = add_nodeint(&head, 98);
add_nodeint(&head, 402);
add_nodeint(&head, 1024);
print_listint_safe(head);
return (0);
}
julien@ubuntu:~/0x13. More singly linked lists$ gcc -Wall -pedantic -Werror -Wextra -std=gnu89 101-main.c 2-add_nodeint.c 101-print_listint_safe.c -o m
julien@ubuntu:~/0x13. More singly linked lists$ ./m
[0x1b500f0] 1024
[0x1b500d0] 402
[0x1b500b0] 98
[0x1b50090] 4
[0x1b50070] 3
[0x1b50050] 2
[0x1b50030] 1
[0x1b50010] 0
[0x1b50600] 1024
[0x1b505e0] 402
[0x1b505c0] 98
[0x1b505a0] 4
[0x1b50580] 3
[0x1b50560] 2
[0x1b50540] 1
[0x1b50110] 0
-> [0x1b505c0] 98
julien@ubuntu:~/0x13. More singly linked lists$
- GitHub repository: holbertonschool-low_level_programming
- Directory: 0x13-more_singly_linked_lists
- File: 101-print_listint_safe.c